aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/atlas.go17
-rw-r--r--debug_shell/debug_shell.go11
-rw-r--r--makefile3
-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()
-}
diff --git a/makefile b/makefile
index 4874d04..6126ea3 100644
--- a/makefile
+++ b/makefile
@@ -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"