Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nitintf committed Mar 24, 2024
1 parent b66546c commit 601a5bf
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 290 deletions.
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ linters:
- tagliatelle
- misspell
- depguard
- testifylint
- gocritic
linters-settings:
staticcheck:
Expand All @@ -39,7 +38,3 @@ linters-settings:
gocritic:
enabled-checks:
- exitAfterDefer
testifylint:
enable-all: true
disable:
- error-is-as # false positive
141 changes: 70 additions & 71 deletions cmd/explain.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,70 @@
package cmd

import (
"github.com/nitintf/navi/internal/ai"
"github.com/nitintf/navi/utils"
"github.com/spf13/cobra"
)

var explainTemplate = `
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge.
Your task is to explain the provided shell command in a way that a beginner could understand in less than 80 words. The explanation should:
* Be clear and concise.
* Avoid technical jargon where possible.
* Not require additional explanation.
Here is the command:
> %s
If the command is not related to shell or terminal, return "NAVI_NAVI_AI_ERROR".
If the command is unclear or ambiguous, return "NAVI_AI_ERROR".
If the command requires additional explanation beyond your capabilities, return "NAVI_AI_ERROR".
If the command is not a shell command, return "NAVI_AI_ERROR".
**Examples:**
* Command: "ls"
* Response: "The 'ls' command lists all files and directories in the current directory."
* Command: "open funny_cat_video.mp4" (Not a shell command)
* Response: "NAVI_AI_ERROR"
`

var explainCmd = &cobra.Command{
Use: "explain",
Short: "Explain - Understand your shell commands",
Example: `navi explain "ls"`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
command := args[0]
commandLength := len(command)

if commandLength > 120 {
utils.LogError("Command is too long. Please keep it under 120 characters.")
return
}

spin := utils.GetSpinner()
spin.Suffix = " Explaining command..."
spin.Start()
resp, err := ai.Generate(cmd.Context(), explainTemplate, command)

if err != nil {
spin.Stop()
utils.LogError(err.Error())
return
}

spin.Stop()
utils.LogExplanation(resp)
},
}

func init() {
rootCmd.AddCommand(explainCmd)
}
package cmd

import (
"github.com/nitintf/navi/internal/ai"
"github.com/nitintf/navi/utils"
"github.com/spf13/cobra"
)

var explainTemplate = `
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge.
Your task is to explain the provided shell command in a way that a beginner could understand in less than 80 words. The explanation should:
* Be clear and concise.
* Avoid technical jargon where possible.
* Not require additional explanation.
Here is the command:
> %s
If the command is not related to shell or terminal, return "NAVI_NAVI_AI_ERROR".
If the command is unclear or ambiguous, return "NAVI_AI_ERROR".
If the command requires additional explanation beyond your capabilities, return "NAVI_AI_ERROR".
If the command is not a shell command, return "NAVI_AI_ERROR".
**Examples:**
* Command: "ls"
* Response: "The 'ls' command lists all files and directories in the current directory."
* Command: "open funny_cat_video.mp4" (Not a shell command)
* Response: "NAVI_AI_ERROR"
`

var explainCmd = &cobra.Command{
Use: "explain",
Short: "Explain - Understand your shell commands",
Example: `navi explain "ls"`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
command := args[0]
commandLength := len(command)

if commandLength > 120 {
utils.LogError("Command is too long. Please keep it under 120 characters.")
return
}

spin := utils.GetSpinner()
spin.Suffix = " Explaining command..."
spin.Start()
resp, err := ai.Generate(cmd.Context(), explainTemplate, command)
if err != nil {
spin.Stop()
utils.LogError(err.Error())
return
}

spin.Stop()
utils.LogExplanation(resp)
},
}

func init() {
rootCmd.AddCommand(explainCmd)
}
163 changes: 81 additions & 82 deletions cmd/navi.go
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
package cmd

import (
"fmt"

"github.com/nitintf/navi/internal/ai"
"github.com/nitintf/navi/utils"
"github.com/spf13/cobra" // Import Cobra library
)

var commandTemplate = `
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge.
Write a single, safe shell command that achieves the desired outcome. The command should:
* Not modify or delete files or folders.
* Be appropriate for a general audience (avoid offensive or harmful commands).
* Not require additional explanation.
Here is the prompt:
> %s
If the prompt is not related to a safe shell command or is not related to shell or commands or terminal, return "NAVI_AI_ERROR".
If the prompt is not appropriate for a general audience, return "NAVI_AI_ERROR".
If the prompt is unclear or ambiguous, return "NAVI_AI_ERROR".
If the prompt requires additional explanation, return "NAVI_AI_ERROR".
If the prompt is not a shell command, return "NAVI_AI_ERROR".
If the prompt is a shell command but is not safe, return "NAVI_AI_ERROR".
**Examples:**
* Prompt: "List all files in the current directory."
* Response: ls
* Prompt: "Delete all files in the current directory." (Unsafe)
* Response: "NAVI_AI_ERROR"
* Prompt: "Show a funny cat video." (Not a shell command)
* Response: "NAVI_AI_ERROR"
`

var rootCmd = &cobra.Command{
Use: "navi",
Short: "Navi - Your AI-powered Shell Guide",
Example: `navi "List all files in the current directory."`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
prompt := args[0]
promptLength := len(prompt)

if promptLength > 120 {
utils.LogError("Prompt is too long. Please keep it under 120 characters.")
return
}

spin := utils.GetSpinner()
spin.Suffix = " Generating command..."
spin.Start()
resp, err := ai.Generate(cmd.Context(), commandTemplate, prompt)

if err != nil {
spin.Stop()
utils.LogError(err.Error())
return
}

spin.Stop()
utils.LogInfo(resp)
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
}
}
package cmd

import (
"fmt"

"github.com/nitintf/navi/internal/ai"
"github.com/nitintf/navi/utils"
"github.com/spf13/cobra" // Import Cobra library
)

var commandTemplate = `
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge.
Write a single, safe shell command that achieves the desired outcome. The command should:
* Not modify or delete files or folders.
* Be appropriate for a general audience (avoid offensive or harmful commands).
* Not require additional explanation.
Here is the prompt:
> %s
If the prompt is not related to a safe shell command or is not related to shell or commands or terminal, return "NAVI_AI_ERROR".
If the prompt is not appropriate for a general audience, return "NAVI_AI_ERROR".
If the prompt is unclear or ambiguous, return "NAVI_AI_ERROR".
If the prompt requires additional explanation, return "NAVI_AI_ERROR".
If the prompt is not a shell command, return "NAVI_AI_ERROR".
If the prompt is a shell command but is not safe, return "NAVI_AI_ERROR".
**Examples:**
* Prompt: "List all files in the current directory."
* Response: ls
* Prompt: "Delete all files in the current directory." (Unsafe)
* Response: "NAVI_AI_ERROR"
* Prompt: "Show a funny cat video." (Not a shell command)
* Response: "NAVI_AI_ERROR"
`

var rootCmd = &cobra.Command{
Use: "navi",
Short: "Navi - Your AI-powered Shell Guide",
Example: `navi "List all files in the current directory."`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
prompt := args[0]
promptLength := len(prompt)

if promptLength > 120 {
utils.LogError("Prompt is too long. Please keep it under 120 characters.")
return
}

spin := utils.GetSpinner()
spin.Suffix = " Generating command..."
spin.Start()
resp, err := ai.Generate(cmd.Context(), commandTemplate, prompt)
if err != nil {
spin.Stop()
utils.LogError(err.Error())
return
}

spin.Stop()
utils.LogInfo(resp)
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
}
}
Loading

0 comments on commit 601a5bf

Please sign in to comment.