Skip to content

Commit

Permalink
struct moving
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Nov 22, 2023
1 parent a5e482d commit ea27a91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ func parseArgs() *assembuddy.CLIOptions {
}
opts.Syscall = *query
opts.Arch = *arch
opts.ListArchQueries = *listArch
opts.ListArch = *listArch
opts.PrettyPrint = *prettyPrint

return opts
}

func main() {
opts := parseArgs()
if opts.ListArchQueries {
if opts.ListArch {
_, err := assembuddy.ArchInfo()
if err != nil {
log.Fatalf("Error: %s", err)
}
}
table, err := assembuddy.GetSyscallData(opts.Arch, opts.Syscall, opts.PrettyPrint)
table, err := assembuddy.GetSyscallData(opts)
if err != nil {
log.Fatal(err)
}
assembuddy.RenderTable(opts.Arch, table)
assembuddy.RenderTable(opts, table)
}
3 changes: 2 additions & 1 deletion pkg/assembuddy/renderTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const (
white = lipgloss.Color("#ffffff")
)

func RenderTable(arch string, tableData []Syscall) {
func RenderTable(opts *CLIOptions, tableData []Syscall) {
arch := opts.Arch
re := lipgloss.NewRenderer(os.Stdout)

var (
Expand Down
17 changes: 9 additions & 8 deletions pkg/assembuddy/requestTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type Syscall struct {
}

type CLIOptions struct {
Syscall string
Arch string
ListArchQueries bool
PrettyPrint bool
Syscall string
Arch string
ListArch bool
PrettyPrint bool
}

func fetchData(endpointURL string, prettyp bool) ([]Syscall, error) {
Expand Down Expand Up @@ -55,7 +55,8 @@ func fetchData(endpointURL string, prettyp bool) ([]Syscall, error) {
return systemCalls, nil
}

func GetSyscallData(arch string, name string, prettyp bool) ([]Syscall, error) {
func GetSyscallData(opts *CLIOptions) ([]Syscall, error) {
arch := opts.Arch
url := "https://api.syscall.sh/v1/syscalls"
// if arch is x64, x86, arm, or arm64, concat to endpointURL
if arch == "x64" || arch == "x86" || arch == "arm" || arch == "arm64" {
Expand All @@ -64,10 +65,10 @@ func GetSyscallData(arch string, name string, prettyp bool) ([]Syscall, error) {
} else if arch != "" {
return nil, errors.New("invalid architecture")
}
if name != "" {
url += "/" + name
if opts.Syscall != "" {
url += "/" + opts.Syscall
}
return fetchData(url, prettyp)
return fetchData(url, opts.PrettyPrint)
}

func ArchInfo() ([]Syscall, error) {
Expand Down

0 comments on commit ea27a91

Please sign in to comment.