Working on it
This commit is contained in:
parent
3ee5d4cc22
commit
845521f1a8
57
main.go
57
main.go
@ -16,6 +16,16 @@ var cfg *userConfig.Config
|
||||
// Valid command line options
|
||||
var validFlags []cliFlag
|
||||
|
||||
const (
|
||||
OpSearch = iota
|
||||
OpAdd
|
||||
OpUpdate
|
||||
OpDelete
|
||||
OpError
|
||||
)
|
||||
|
||||
var performOp = OpSearch
|
||||
|
||||
func main() {
|
||||
err := initialize()
|
||||
if err != nil {
|
||||
@ -23,11 +33,24 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// If no command line options are given, go into gui mode
|
||||
if len(os.Args) > 1 {
|
||||
fmt.Println(os.Args[1])
|
||||
if os.Args[1] == "-a" {
|
||||
// Adding a new bookmark
|
||||
parms := os.Args
|
||||
if len(parms) > 1 {
|
||||
parms = parms[1:]
|
||||
for _, v := range parms {
|
||||
switch v {
|
||||
case "-h":
|
||||
printUsage()
|
||||
os.Exit(0)
|
||||
case "-a":
|
||||
// Adding a new bookmark
|
||||
setOperation(OpAdd)
|
||||
case "-u":
|
||||
// Updating an existing bookmark
|
||||
setOperation(OpUpdate)
|
||||
case "-d":
|
||||
// Delete an existing bookmark
|
||||
setOperation(OpDelete)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Enter cui mode
|
||||
@ -35,13 +58,25 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func setOperation(which int) {
|
||||
if performOp != OpSearch || which >= OpError {
|
||||
// We've already tried to set the operation
|
||||
fmt.Println("Error parsing command. For help use '-h'.")
|
||||
os.Exit(1)
|
||||
}
|
||||
performOp = which
|
||||
}
|
||||
|
||||
// initialize sets up the application for general use
|
||||
func initialize() error {
|
||||
var err error
|
||||
// Build the list of valid command line options
|
||||
addValidFlag("-a", "add", []string{"Add a new bookmark"})
|
||||
addValidFlag("-h", "help", []string{"Print the usage (this message)"})
|
||||
addValidFlag("-n", "name", []string{
|
||||
addValidFlag("-a", "add", []string{"Add a new bookmark"})
|
||||
addValidFlag("-u", "update", []string{"Update an existing bookmark"})
|
||||
addValidFlag("-d", "delete", []string{"Delete an existing bookmark"})
|
||||
addValidFlag("-s", "search", []string{"Search for a bookmark"})
|
||||
addValidFlag("-n", "name (optional)", []string{
|
||||
"When adding/updating, specify the name you wish to give a bookmark.",
|
||||
"When searching, specifiy the name of the bookmark(s) you're searching for.",
|
||||
})
|
||||
@ -50,7 +85,6 @@ func initialize() error {
|
||||
"When adding/updating, specify the tags you wish to give a bookmark.",
|
||||
"When searching, specifiy the name of the tags you're searching for.",
|
||||
})
|
||||
addValidFlag("-u", "update", []string{"Update an existing bookmark"})
|
||||
|
||||
// Load the config
|
||||
cfg, err = userConfig.NewConfig(AppName)
|
||||
@ -89,9 +123,10 @@ func printUsage() {
|
||||
"mark is a tool for keeping your bookmarks organized",
|
||||
"",
|
||||
"Usage: ",
|
||||
"\tmark",
|
||||
"\tmark [operation] [optional flags]",
|
||||
"",
|
||||
"If no arguments are given, we enter gui mode",
|
||||
"If no 'operation' arguments are given (-a, -u, -d, -s) search is assumed",
|
||||
"",
|
||||
"Valid arguments are:",
|
||||
"",
|
||||
@ -100,9 +135,9 @@ func printUsage() {
|
||||
fmt.Println(ln)
|
||||
}
|
||||
for _, v := range validFlags {
|
||||
fmt.Println(v.Flag, "\t", v.Name)
|
||||
fmt.Println("\t", v.Flag, "\t", v.Name)
|
||||
for _, hv := range v.Description {
|
||||
fmt.Println("\t", hv)
|
||||
fmt.Println("\t\t\t", hv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user