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 <julien@riou.xyz>
This commit is contained in:
parent
463e2e703b
commit
d43c645039
3 changed files with 35 additions and 10 deletions
|
@ -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: ")
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue