From d43c6450392c23f92b7e164b693aea7c6bae3382 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Thu, 28 Aug 2025 12:44:36 +0200 Subject: [PATCH] Several changes to clients coller: - Add FILENAME as positioned argument (fixes #18) - Add -html argument to show the URL of the webpage copier: - Rename -w to -ask-password both: - Rename -b to -ask-bearer Signed-off-by: Julien Riou --- src/cmd/coller/main.go | 39 ++++++++++++++++++++++++++++++++------- src/cmd/copier/main.go | 4 ++-- src/internal/utils.go | 2 +- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/cmd/coller/main.go b/src/cmd/coller/main.go index c1d95a8..dc75eab 100644 --- a/src/cmd/coller/main.go +++ b/src/cmd/coller/main.go @@ -52,6 +52,10 @@ func handleMain() int { return internal.RC_ERROR } + flag.Usage = usage + + var fileName string + version := flag.Bool("version", false, "Print version and exit") quiet := flag.Bool("quiet", false, "Log errors only") verbose := flag.Bool("verbose", false, "Print more logs") @@ -63,16 +67,24 @@ func handleMain() int { askPassword := flag.Bool("ask-password", false, "Read password from input") noPassword := flag.Bool("no-password", false, "Allow notes without password") passwordLength := flag.Int("password-length", 16, "Length of the auto-generated password") - fileName := flag.String("file", "", "Read content of the note from a file") + flag.StringVar(&fileName, "file", "", "Read content of the note from a file") expiration := flag.Int("expiration", 0, "Number of seconds before expiration") deleteAfterRead := flag.Bool("delete-after-read", false, "Delete the note after the first read") copier := flag.Bool("copier", false, "Print the copier command to decrypt the note") + html := flag.Bool("html", false, "Print the HTML version of the note") bearer := flag.String("bearer", os.Getenv("COLLER_BEARER"), "Bearer token") - askBearer := flag.Bool("b", false, "Read bearer token from input") + askBearer := flag.Bool("ask-bearer", false, "Read bearer token from input") language := flag.String("language", "", "Language of the note") flag.Parse() + if flag.NArg() == 1 { + fileName = flag.Args()[0] + } else if flag.NArg() > 1 { + usage() + return internal.RC_ERROR + } + if *version { internal.ShowVersion(AppName, AppVersion, GitCommit, GoVersion) return internal.RC_OK @@ -113,9 +125,9 @@ func handleMain() int { } var content []byte - if *fileName != "" { - logger.Debug("reading from file", slog.Any("file", *fileName)) - content, err = os.ReadFile(*fileName) + if fileName != "" { + logger.Debug("reading from file", slog.Any("file", fileName)) + content, err = os.ReadFile(fileName) if err != nil { return internal.ReturnError(logger, "could not read from file", err) } @@ -233,10 +245,18 @@ func handleMain() int { if *copier { location = fmt.Sprintf("copier -password %s %s", *password, noteURL) } else { - location = fmt.Sprintf("%s/%s", noteURL, *password) + if *html { + location = fmt.Sprintf("%s/%s.html", noteURL, *password) + } else { + location = fmt.Sprintf("%s/%s", noteURL, *password) + } } } else { - location = fmt.Sprintf("%s", noteURL) + if *html { + location = fmt.Sprintf("%s.html", noteURL) + } else { + location = fmt.Sprintf("%s", noteURL) + } } logger.Debug("displaying note location") @@ -249,6 +269,11 @@ func main() { os.Exit(handleMain()) } +func usage() { + fmt.Printf("Usage: %s [OPTIONS] [FILENAME]\n", os.Args[0]) + flag.PrintDefaults() +} + func CreateConfig() Config { var url string fmt.Print("Instance URL: ") diff --git a/src/cmd/copier/main.go b/src/cmd/copier/main.go index 611d146..73c18d3 100644 --- a/src/cmd/copier/main.go +++ b/src/cmd/copier/main.go @@ -29,10 +29,10 @@ func handleMain() int { verbose := flag.Bool("verbose", false, "Print more logs") debug := flag.Bool("debug", false, "Print even more logs") password := flag.String("password", os.Getenv("COLLER_PASSWORD"), "Password to decrypt the note") - askPassword := flag.Bool("w", false, "Read password from input") + askPassword := flag.Bool("ask-password", false, "Read password from input") fileName := flag.String("file", "", "Write content of the note to a file") bearer := flag.String("bearer", os.Getenv("COLLER_BEARER"), "Bearer token") - askBearer := flag.Bool("b", false, "Read bearer token from input") + askBearer := flag.Bool("ask-bearer", false, "Read bearer token from input") flag.Parse() diff --git a/src/internal/utils.go b/src/internal/utils.go index d522bc7..c98c2e3 100644 --- a/src/internal/utils.go +++ b/src/internal/utils.go @@ -38,7 +38,7 @@ func Version(appName, appVersion, gitCommit, goVersion string) string { version += "-" + gitCommit } if goVersion != "" { - version += " (compiled with Go " + goVersion + ")" + version += " (compiled with " + goVersion + ")" } return version }