mirror of
https://github.com/thunderbrewhq/binana.git
synced 2026-04-17 15:33:54 +00:00
feat(bna): add 'as' subcommand to add symbols
Some checks failed
Push / build (push) Has been cancelled
Some checks failed
Push / build (push) Has been cancelled
This commit is contained in:
parent
b62710fe15
commit
362bf7f31b
8 changed files with 300 additions and 3 deletions
71
go/app/cmd/add_symbol/add_symbol.go
Normal file
71
go/app/cmd/add_symbol/add_symbol.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package add_symbol
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
"github.com/thunderbrewhq/binana/go/app/profile"
|
||||
"github.com/thunderbrewhq/binana/go/symbols"
|
||||
)
|
||||
|
||||
func as_func(cmd *cobra.Command, args []string) {
|
||||
f := cmd.Flags()
|
||||
var (
|
||||
err error
|
||||
params profile.AddSymbolParams
|
||||
)
|
||||
params.Profile = args[0]
|
||||
params.Group, err = f.GetString("group")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// TODO: infer the group
|
||||
if params.Group == "" {
|
||||
app.Fatal("pass in the group (-g, --group) that will store the symbol(s)")
|
||||
return
|
||||
}
|
||||
if len(args) < 2 {
|
||||
// read normally formatted symbols from stdin
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
var symbol symbols.Symbol
|
||||
if err = symbol.Parse(line); err != nil {
|
||||
app.Fatal(err)
|
||||
return
|
||||
}
|
||||
params.Symbols = append(params.Symbols, symbol)
|
||||
}
|
||||
} else {
|
||||
// use args to add symbol
|
||||
if len(args) < 4 {
|
||||
cmd.Help()
|
||||
return
|
||||
}
|
||||
params.Symbols = make([]symbols.Symbol, 1)
|
||||
if err = params.Symbols[0].ParseCommandLine(args[1:]); err != nil {
|
||||
return
|
||||
}
|
||||
params.Symbols[0].Comment, err = f.GetString("comment")
|
||||
}
|
||||
|
||||
profile.AddSymbol(¶ms)
|
||||
}
|
||||
|
||||
var as_cmd = cobra.Command{
|
||||
Use: "as profile [symbol_name] [address] [l|f] [type=...]",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Short: "Add symbols to profile",
|
||||
Long: "Adds symbol passed through command-line arguments, or add one or more normally-formatted symbols by passing them through stdin",
|
||||
Run: as_func,
|
||||
}
|
||||
|
||||
func init() {
|
||||
f := as_cmd.Flags()
|
||||
f.StringP("group", "g", "", "the profile symbol group to record symbols into (e.g. 'feature1' to record into profile/<profile>/symbol/feature1)")
|
||||
f.StringP("comment", "m", "", "the comment to pass to the symbol")
|
||||
root.RootCmd.AddCommand(&as_cmd)
|
||||
}
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/add_symbol"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/lint"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/make"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/tidy"
|
||||
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
)
|
||||
|
||||
func Execute() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package cmd
|
|||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
"github.com/thunderbrewhq/binana/go/app/profile"
|
||||
)
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ func init() {
|
|||
f := lint_cmd.Flags()
|
||||
f.Bool("bounds", false, "check for bad function boundaries")
|
||||
f.Bool("constructors", false, "check for outdated class constructor names")
|
||||
root.RootCmd.AddCommand(&lint_cmd)
|
||||
}
|
||||
|
||||
func lint_func(cmd *cobra.Command, args []string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue