func sources(client service.Client, filter string) ([]string, error) { return client.ListSources(filter) }
func info(client service.Client, args ...string) error { if len(args) == 0 { return fmt.Errorf("not enough arguments. expected info type [regex].") } // Allow for optional regex var filter *regexp.Regexp if len(args) >= 2 { var err error if filter, err = regexp.Compile(args[1]); err != nil { return fmt.Errorf("invalid filter argument: %s", err.Error()) } } var data []string switch args[0] { case "sources": regex := "" if len(args) >= 2 && len(args[1]) > 0 { regex = args[1] } sources, err := client.ListSources(regex) if err != nil { return err } data = sources case "funcs": regex := "" if len(args) >= 2 && len(args[1]) > 0 { regex = args[1] } funcs, err := client.ListFunctions(regex) if err != nil { return err } data = funcs case "regs": regs, err := client.ListRegisters() if err != nil { return err } data = append(data, regs) case "args": args, err := client.ListFunctionArgs() if err != nil { return err } data = filterVariables(args, filter) case "locals": locals, err := client.ListLocalVariables() if err != nil { return err } data = filterVariables(locals, filter) case "vars": regex := "" if len(args) >= 2 && len(args[1]) > 0 { regex = args[1] } vars, err := client.ListPackageVariables(regex) if err != nil { return err } data = filterVariables(vars, filter) default: return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources or vars") } // sort and output data sort.Sort(sort.StringSlice(data)) for _, d := range data { fmt.Println(d) } return nil }