Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Nov 16, 2023
1 parent 42ab39b commit 44cf524
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 101 deletions.
26 changes: 10 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import (
"fmt"
"os"

"github.com/Selyss/AssemBuddy/pkg/assembuddy"
"github.com/akamensky/argparse"
// tea "github.com/charmbracelet/bubbletea"
)

type CLIOptions struct {
Query string
Architecture string
ListQueryMatches bool
ListArchQueries bool
}

func parseArgs() *CLIOptions {
options := &CLIOptions{}
func parseArgs() *assembuddy.CLIOptions {
opts := &assembuddy.CLIOptions{}

parser := argparse.NewParser("AssemBuddy", "Tool for querying assembly keywords")
query := parser.String("q", "query", &argparse.Options{Help: "Search query"})
Expand All @@ -30,15 +24,15 @@ func parseArgs() *CLIOptions {
fmt.Print(parser.Usage(err))
}

options.Query = *query
options.Architecture = *arch
options.ListQueryMatches = *listQueryMatches
options.ListArchQueries = *listArchQueries
opts.Syscall = *query
opts.Arch = *arch
opts.ListQueryMatches = *listQueryMatches
opts.ListArchQueries = *listArchQueries

return options
return opts
}

func main() {
options := parseArgs()
fmt.Println(options)
opts := parseArgs()
assembuddy.QueryASM(opts)
}
29 changes: 13 additions & 16 deletions pkg/assembuddy/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"log"
"net/http"
"os"
)

type Syscall struct {
Expand All @@ -23,27 +22,25 @@ type Syscall struct {
Arg5 string `json:"arg5"`
}

func QueryASM() {
archs := []string{"x64", "x86", "arm", "arm64"}
type CLIOptions struct {
Syscall string
Arch string
ListQueryMatches bool
ListArchQueries bool
}

arch, err := SelectFromList(archs)
if err != nil {
log.Fatalf("Error selecting a language: %s", err)
}
func QueryASM(opts *CLIOptions) {
arch := opts.Arch
syscall := opts.Syscall

syscalls, err := getSyscalls(arch)
if err != nil {
log.Fatalf("Error fetching syscalls for %s: %s", arch, err)
}
var selectedName string

selectedName, err := SelectFromList(syscalls)
if err != nil {
log.Fatalf("Error selecting a syscall: %s", err)
if syscall != "" {
selectedName = syscall
}

if selectedName == "" {
fmt.Println("No syscall selected.")
os.Exit(0)
log.Fatalf("No syscall selected.")
}

selectedSyscall, err := getSyscallDetails(arch, selectedName)
Expand Down
69 changes: 0 additions & 69 deletions pkg/assembuddy/spinner.go

This file was deleted.

0 comments on commit 44cf524

Please sign in to comment.