added command line argument stuffs

This commit is contained in:
boofnet
2022-04-12 23:52:39 -04:00
parent d9538312d2
commit 771820e075
+49 -12
View File
@@ -1,7 +1,7 @@
// ============================================================================= // =============================================================================
// Auth: Alex Celani // Auth: Alex Celani
// File: tdm.go // File: tdm.go
// Revn: 04-11-2022 3.3 // Revn: 04-12-2022 5.0
// //
// Func: display and manage progress of a litany of items to be done, // Func: display and manage progress of a litany of items to be done,
// with an organization scheme similar to Trello. It's CLI // with an organization scheme similar to Trello. It's CLI
@@ -9,11 +9,9 @@
// //
// TODO: add debug statements // TODO: add debug statements
// //
// fix issue where fileIn() breaks on empty board
// add second object to hold command information // add second object to hold command information
// make subsubtasks for greater depth // make subsubtasks for greater depth
// M or rooms to contain boards // M or rooms to contain boards
// handle command line args
// M remember last args // M remember last args
// move most (read: all) helper functions to external files // move most (read: all) helper functions to external files
// M add priority to tasks // M add priority to tasks
@@ -112,8 +110,10 @@
// 04-07-2022: fixed bug where task fill did not persist when task // 04-07-2022: fixed bug where task fill did not persist when task
// contained subtasks // contained subtasks
// 04-10-2022: changed type of fill in task/subtask from int to string // 04-10-2022: changed type of fill in task/subtask from int to string
// 04-11-2022: wrote, tested, and integrated calc() into show() and //*04-11-2022: wrote, tested, and integrated calc() into show() and
// сделай() // сделай()
//*04-12-2022: calls to os.Args in main() to work with cmd line args
// fixed bug where fileIn() crashes on empty board
// //
// ============================================================================= // =============================================================================
@@ -124,7 +124,7 @@ import (
"fmt" // used for Println "fmt" // used for Println
"strings" // used for Split, ToLower, Join "strings" // used for Split, ToLower, Join
"strconv" // used for Atoi "strconv" // used for Atoi
"os" // used for Exit, Stdin "os" // used for Exit, Stdin, Args
"os/signal" // used for Notify "os/signal" // used for Notify
"syscall" // used for SIGTERM "syscall" // used for SIGTERM
"io/ioutil" // used for ReadFile, WriteFile "io/ioutil" // used for ReadFile, WriteFile
@@ -199,7 +199,7 @@ func catch() {
print( "\r" ) // this helps with the missing newline print( "\r" ) // this helps with the missing newline
exit( 0 ) // and exit gracefully exit( 0 ) // and exit gracefully
}() }()
} }
@@ -380,6 +380,15 @@ func fileIn() {
print( "board name -> ", bName ) print( "board name -> ", bName )
} }
// if there is no text right of the task marker
if len( bTasks ) == 0 {
// literally just initialize a new empty array of tasks
// and add to the map with the board name
boards[bName] = []task{}
continue // jump to the next board because
// there's no contents to process
}
// separate tasks from each other // separate tasks from each other
tTasks := split( bTasks, ";" ) tTasks := split( bTasks, ";" )
var tk task // make empty task var tk task // make empty task
@@ -1585,18 +1594,36 @@ func main() {
for { // infinite loop, where everything happens for { // infinite loop, where everything happens
userIn := input( "-> " ) // take user input // declare array of strings to contain user input
ui := split( userIn, " " ) // split over spaces var ui []string
// and quick flag to keep track of operation mode:
// cmd line args or inline?
var cmd bool = false
// check to see if there was a given argument
if len( os.Args[1:] ) > 0 { // if yes
ui = os.Args[1:] // declare ui as list of args
// XXX
if flag { // if debug set, print arguments list
print( ui )
}
cmd = true // set cmd line args flag
} else { // if no
userIn := input( "-> " ) // take user input
ui = split( userIn, " " ) // split over spaces
}
command := ui[0] // first entry is command command := ui[0] // first entry is command
// convention: send entire array to subfunction, do not strip // convention: send entire array to subfunction, do not strip
// any subcommands off // any subcommands off
// switch case over command // process the user input
// recognize user input, call appropriate command
var search query = parse( ui ) var search query = parse( ui )
// switch case over command
// recognize user input, call appropriate command
switch command { switch command {
case "delete": case "delete":
del( search ) del( search )
@@ -1617,6 +1644,7 @@ func main() {
show( search ) show( search )
case "exit", "quit": case "exit", "quit":
// XXX
if flag { // if debug set, print if file was changed if flag { // if debug set, print if file was changed
print( changed ) print( changed )
} }
@@ -1637,6 +1665,15 @@ func main() {
default: // if the input is unrecognized default: // if the input is unrecognized
continue // try again continue // try again
} }
// if cmd line arg mode, only run once, break infinite loop
if cmd {
// if file was changed, rewrite to file
if changed {
fileOut()
}
break
}
} }
} }