Skip to content

Commit d975a5b

Browse files
committed
Add alias for install, repo context support in count command
1 parent f3d6745 commit d975a5b

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

Justfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ install: build
2929
rm -rf $GOPATH/bin/otto
3030
cp bin/otto $GOPATH/bin
3131

32+
i: install
33+
3234
add command:
3335
cobra-cli add {{command}}
3436

cmd/count.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/chand1012/ottodocs/pkg/calc"
1111
"github.com/chand1012/ottodocs/pkg/config"
12+
"github.com/chand1012/ottodocs/pkg/git"
1213
"github.com/chand1012/ottodocs/pkg/utils"
1314
"github.com/spf13/cobra"
1415
)
@@ -32,7 +33,7 @@ otto count -c contextfile.txt -g "prompt"`,
3233

3334
var prompt string
3435

35-
if chatPrompt == "" && len(contextFiles) == 0 {
36+
if chatPrompt == "" && len(contextFiles) == 0 && !repoContext {
3637
log.Error("Requires a prompt or context file as an argument. Example: otto count -c contextfile.txt -g \"prompt\"")
3738
os.Exit(1)
3839
}
@@ -41,13 +42,26 @@ otto count -c contextfile.txt -g "prompt"`,
4142
prompt = "GOAL:" + chatPrompt
4243
}
4344

44-
for _, contextFile := range contextFiles {
45-
content, err := utils.LoadFile(contextFile)
45+
if repoContext {
46+
repo, err := git.GetRepo(".", "", false)
4647
if err != nil {
47-
log.Errorf("Error loading file: %s", err)
48+
log.Errorf("Error getting repo: %s", err)
4849
os.Exit(1)
4950
}
50-
prompt += "\n\nFILE: " + contextFile + "\n\n" + content + "\n"
51+
52+
for _, file := range repo.Files {
53+
content := file.Contents
54+
prompt += "\n\nFILE: " + file.Path + "\n\n" + content + "\n"
55+
}
56+
} else {
57+
for _, contextFile := range contextFiles {
58+
content, err := utils.LoadFile(contextFile)
59+
if err != nil {
60+
log.Errorf("Error loading file: %s", err)
61+
os.Exit(1)
62+
}
63+
prompt += "\n\nFILE: " + contextFile + "\n\n" + content + "\n"
64+
}
5165
}
5266

5367
tokens, err := calc.PreciseTokens(prompt)
@@ -66,4 +80,5 @@ func init() {
6680

6781
countCmd.Flags().StringVarP(&chatPrompt, "goal", "g", "", "Prompt for token count")
6882
countCmd.Flags().StringSliceVarP(&contextFiles, "context", "c", []string{}, "Context files")
83+
countCmd.Flags().BoolVarP(&repoContext, "repo", "r", false, "Use the current repository as context")
6984
}

0 commit comments

Comments
 (0)