diff --git a/.gitignore b/.gitignore index 1a88cbd..0166a61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .aider* .env *.png +gonamer diff --git a/README.md b/README.md index 1066c15..3e397e1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Gonamer is a command-line tool written in Go that uses any openai compatible vi ## Features -- Uses OpenAI's vision model to analyze image content +- Uses any OpenAI compatible vision model to analyze image content - Supports JPG, JPEG, PNG, and GIF formats - Generates unique, descriptive filenames - Handles filename conflicts automatically @@ -22,7 +22,9 @@ go get gopkg.in/yaml.v3 ## Configuration -Create a configuration file at `~/.config/gonamer.yaml` with the following structure: +By default, Gonamer looks for a configuration file at `~/.config/gonamer.yaml`. You can also specify a custom configuration file using the `-c` flag. + +Create a configuration file with the following structure: ```yaml apikey: "your-api-key" @@ -38,12 +40,16 @@ Make sure to replace: ## Usage ```bash -gonamer +gonamer [-c config.yaml] ``` For example: ```bash +# Using default config at ~/.config/gonamer.yaml gonamer vacation_photo.jpg + +# Using a custom config file +gonamer -c custom-config.yaml vacation_photo.jpg ``` The tool will: diff --git a/gonamer b/gonamer new file mode 100755 index 0000000..dc3676e Binary files /dev/null and b/gonamer differ diff --git a/gonamer.go b/gonamer.go index 399b99c..00065a2 100644 --- a/gonamer.go +++ b/gonamer.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "encoding/json" + "flag" "fmt" "io" "io/ioutil" @@ -31,7 +32,7 @@ type OpenAIRequest struct { // Message represents a message in the OpenAI API request. type Message struct { - Role string `json:"role"` + Role string `json:"role"` Content []Content `json:"content"` } @@ -63,8 +64,12 @@ type Config struct { } func main() { + var configFile string + flag.StringVar(&configFile, "c", "", "Path to config file") + flag.Parse() + // Get the config file path - configFilePath, err := getConfigFilePath() + configFilePath, err := getConfigFilePath(configFile) if err != nil { log.Fatalf("Error getting config file path: %v", err) } @@ -76,11 +81,12 @@ func main() { } // Get the image filename from the command-line arguments - if len(os.Args) < 2 { - fmt.Println("Usage: go run main.go ") + if len(flag.Args()) < 1 { + fmt.Println("Usage: gonamer [-c config.yaml] ") + flag.PrintDefaults() return } - imageFilename := os.Args[1] + imageFilename := flag.Arg(0) // Validate the image filename extension if !ImageExtensionRegex.MatchString(imageFilename) { @@ -106,7 +112,10 @@ func main() { } // getConfigFilePath returns the path to the config file. -func getConfigFilePath() (string, error) { +func getConfigFilePath(configFile string) (string, error) { + if configFile != "" { + return configFile, nil + } homeDir, err := os.UserHomeDir() if err != nil { return "", err @@ -141,8 +150,8 @@ func getSuggestedFilename(imageFilename string, config *Config) (string, error) // 2. Create the request payload requestData := OpenAIRequest{ - Model: config.Model, - Messages: []Message{ + Model: config.Model, + Messages: []Message{ { Role: "user", Content: []Content{ @@ -335,7 +344,7 @@ func sanitizeFilename(filename string) string { // Replace invalid characters with underscores sanitizedFilename := invalidChars.ReplaceAllString(filenameWithoutExt, "_") - // Remove non-letter characters from the beginning of the filename + // Remove non-letter characters from the beginning of the filename for len(sanitizedFilename) > 0 && !unicode.IsLetter(rune(sanitizedFilename[0])) { sanitizedFilename = sanitizedFilename[1:] }