diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-06-13 12:35:37 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-06-13 12:35:37 -0400 |
| commit | f85cfb2055551926ed4aeaa0550330d3e4da7569 (patch) | |
| tree | 8ac67405b961c3609ab6fbd9488c826ab81b3e97 | |
| parent | bf841d00967c3047bff88dbe070cb56319e1fe38 (diff) | |
Move debug shell into main binary as a command
| -rw-r--r-- | cmd/atlas.go | 17 | ||||
| -rw-r--r-- | debug_shell/debug_shell.go | 11 | ||||
| -rw-r--r-- | makefile | 3 | ||||
| -rw-r--r-- | pkg/shell/interpreter.go (renamed from debug_shell/interpreter.go) | 2 | ||||
| -rw-r--r-- | pkg/shell/state.go (renamed from debug_shell/state.go) | 2 |
5 files changed, 17 insertions, 18 deletions
diff --git a/cmd/atlas.go b/cmd/atlas.go index a6d161a..f411a2b 100644 --- a/cmd/atlas.go +++ b/cmd/atlas.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "io" "log/slog" "os" "runtime" @@ -13,6 +14,7 @@ import ( "github.com/jpappel/atlas/pkg/data" "github.com/jpappel/atlas/pkg/index" "github.com/jpappel/atlas/pkg/query" + "github.com/jpappel/atlas/pkg/shell" ) const ExitCommand = 2 // exit because of a command parsing error @@ -38,10 +40,11 @@ func addGlobalFlagUsage(fs *flag.FlagSet) func() { func printHelp() { fmt.Println("atlas is a note indexing and querying tool") - fmt.Printf("\nUsage:\n %s <command>\n\n", os.Args[0]) + fmt.Printf("\nUsage:\n %s [global-flags] <command>\n\n", os.Args[0]) fmt.Println("Commands:") fmt.Println(" index - build, update, or modify the index") fmt.Println(" query - search against the index") + fmt.Println(" shell - start a debug query shell") fmt.Println(" help - print this help then exit") } @@ -55,9 +58,11 @@ func main() { indexFs := flag.NewFlagSet("index flags", flag.ExitOnError) queryFs := flag.NewFlagSet("query flags", flag.ExitOnError) + shellFs := flag.NewFlagSet("debug shell flags", flag.ExitOnError) indexFs.Usage = addGlobalFlagUsage(indexFs) queryFs.Usage = addGlobalFlagUsage(queryFs) + shellFs.Usage = addGlobalFlagUsage(shellFs) flag.Parse() args := flag.Args() @@ -71,7 +76,7 @@ func main() { Filters []index.DocFilter }{} - if len(args) < 2 { + if len(args) < 1 { fmt.Fprintln(os.Stderr, "No Command provided") printHelp() fmt.Fprintln(flag.CommandLine.Output(), "\nGlobal Flags:") @@ -129,6 +134,8 @@ func main() { printHelp() flag.PrintDefaults() os.Exit(0) + case "shell": + shellFs.Parse(args[1:]) default: fmt.Fprintln(os.Stderr, "Unrecognized command: ", command) printHelp() @@ -197,6 +204,12 @@ func main() { if err := querier.Put(idx); err != nil { panic(err) } + case "shell": + state := make(shell.State) + interpreter := shell.NewInterpreter(state, os.Stdin) + if err := interpreter.Run(); err != nil && err != io.EOF { + os.Exit(1) + } } } diff --git a/debug_shell/debug_shell.go b/debug_shell/debug_shell.go deleted file mode 100644 index 2ddf467..0000000 --- a/debug_shell/debug_shell.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import "os" - -func main() { - // TODO: command line args - state := make(State) - interpreter := NewInterpreter(state, os.Stdin) - - interpreter.Run() -} @@ -9,9 +9,6 @@ all: $(BINS) atlas: $(SRC) go build -o $@ ./cmd/atlas.go -query_shell: $(wildcard ./debug_shell//*.go) $(wildcard pkg/*/*.go) - go build -o $@ $(wildcard ./debug_shell/*.go) - test: go test ./... diff --git a/debug_shell/interpreter.go b/pkg/shell/interpreter.go index ec4df44..2efce01 100644 --- a/debug_shell/interpreter.go +++ b/pkg/shell/interpreter.go @@ -1,4 +1,4 @@ -package main +package shell import ( "bufio" diff --git a/debug_shell/state.go b/pkg/shell/state.go index 17d0474..ea62604 100644 --- a/debug_shell/state.go +++ b/pkg/shell/state.go @@ -1,4 +1,4 @@ -package main +package shell import ( "errors" |
