let tdm work in any directory

This commit is contained in:
boofnet
2022-04-14 23:07:53 -04:00
parent 771820e075
commit 191a27f8f8
+51 -17
View File
@@ -1,13 +1,13 @@
// ============================================================================= // =============================================================================
// Auth: Alex Celani // Auth: Alex Celani
// File: tdm.go // File: tdm.go
// Revn: 04-12-2022 5.0 // Revn: 04-14-2022 5.1
// //
// 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
// Trello // Trello
// //
// TODO: add debug statements // TODO: rewrite help
// //
// add second object to hold command information // add second object to hold command information
// make subsubtasks for greater depth // make subsubtasks for greater depth
@@ -16,7 +16,6 @@
// 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
// attach text files??? // attach text files???
// fix data storage issue
// contemplate adding XOR of data in file, altho who cares // contemplate adding XOR of data in file, altho who cares
// contemplate adding battery of tests // contemplate adding battery of tests
// contemplate moving functions to external file // contemplate moving functions to external file
@@ -114,6 +113,10 @@
// сделай() // сделай()
//*04-12-2022: calls to os.Args in main() to work with cmd line args //*04-12-2022: calls to os.Args in main() to work with cmd line args
// fixed bug where fileIn() crashes on empty board // fixed bug where fileIn() crashes on empty board
// 04-14-2022: moved data file to home directory with os.UserHomeDir()
// changed arguments for fileIn() and fileOut()
// added quick little subcommands in show() and parse()
// /show/ to print boards or tasks
// //
// ============================================================================= // =============================================================================
@@ -124,7 +127,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, Args "os" // used for Exit, Stdin, Args, UserHomeDir
"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
@@ -141,6 +144,7 @@ var lower = strings.ToLower
var atoi = strconv.Atoi var atoi = strconv.Atoi
var itoa = strconv.Itoa var itoa = strconv.Itoa
var exit = os.Exit var exit = os.Exit
var dir = os.UserHomeDir
var read = ioutil.ReadFile var read = ioutil.ReadFile
var write = ioutil.WriteFile var write = ioutil.WriteFile
@@ -193,7 +197,7 @@ func catch() {
<-c // immediately halts in blocking read for signal <-c // immediately halts in blocking read for signal
if changed { // if there was a change to the map... if changed { // if there was a change to the map...
fileOut() // rewrite data file fileOut( home ) // rewrite data file
} }
print( "\r" ) // this helps with the missing newline print( "\r" ) // this helps with the missing newline
@@ -234,7 +238,7 @@ func join( subcommands []string ) string {
// FILEOUT // FILEOUT
// wrapper function to contain all the file writing // wrapper function to contain all the file writing
func fileOut() { func fileOut( home string ) {
// initialize data to be written as empty string // initialize data to be written as empty string
var data string = "" var data string = ""
@@ -309,7 +313,7 @@ func fileOut() {
// cast writestring to byte array, write to file named "data" // cast writestring to byte array, write to file named "data"
// if a file doesn't exist, make with 0x644 permissions // if a file doesn't exist, make with 0x644 permissions
// take error as err, if fails // take error as err, if fails
err := write( "data", []byte( data ), 0644 ) err := write( home + "/data", []byte( data ), 0644 )
if flag { // if debug set, print data written if flag { // if debug set, print data written
print( data ) print( data )
@@ -325,7 +329,7 @@ func fileOut() {
// FILEIN // FILEIN
// warpper function to contain all the file reading // warpper function to contain all the file reading
func fileIn() { func fileIn( home string ) {
// test string to use in lieu of a file // test string to use in lieu of a file
// file := // file :=
@@ -348,7 +352,7 @@ func fileIn() {
// >30 >30 ~ subtask fill // >30 >30 ~ subtask fill
// > > ~ subtask fill delim // > > ~ subtask fill delim
file, err := read( "data" ) // open file, failure set err file, err := read( home + "/data" ) // open file, failure set err
// declare board, because if statement gets mad if I don't // declare board, because if statement gets mad if I don't
var board []string var board []string
@@ -1011,7 +1015,7 @@ func mark( search query ) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// PARSE( commands []string ) // PARSE( commands []string )
// //
// Revn: 03-27-2022 // Revn: 04-14-2022
// Args: commands - []string // Args: commands - []string
// list of commands of what board, task, or subtask // list of commands of what board, task, or subtask
// to make // to make
@@ -1044,6 +1048,8 @@ func mark( search query ) {
// 03-27-2022: fixed bug in /make/ where tasks under boards with // 03-27-2022: fixed bug in /make/ where tasks under boards with
// names of length 1 failed ( literally changed "> 1" // names of length 1 failed ( literally changed "> 1"
// to "> 0" ) // to "> 0" )
// 04-14-2022: added recognition to /boards/ and /tasks/ subcommand
// inside of /show/
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
func parse( commands []string ) query { func parse( commands []string ) query {
@@ -1064,7 +1070,7 @@ func parse( commands []string ) query {
// big switch statement over command // big switch statement over command
switch comm { switch comm {
// these don't really need processing, break out immediately // these don't really need processing, break out immediately
case "save", "set", "quit", "exit", "calc": case "save", "set", "quit", "exit":
return search return search
case "delete": case "delete":
// there are only so many types of commands that work here // there are only so many types of commands that work here
@@ -1105,8 +1111,6 @@ func parse( commands []string ) query {
search.board = join( subcommands[:] ) search.board = join( subcommands[:] )
} }
} }
case "help":
// help( subcommands )
case "make": case "make":
// -> make <board> // -> make <board>
// -> make board <b> // -> make board <b>
@@ -1266,6 +1270,12 @@ func parse( commands []string ) query {
search.subA = "all" search.subA = "all"
} else { } else {
switch subcommands[0] { switch subcommands[0] {
case "boards", "tasks":
// show boards
// show tasks
// iterate through just the names of the
// boards/tasks
search.subA = subcommands[0]
case "task": case "task":
// show task xyz // show task xyz
// set focus to task // set focus to task
@@ -1445,6 +1455,12 @@ func show( search query ) {
help( showFailure ) help( showFailure )
return return
} }
case "boards":
// literally just print the names of all the boards
// just a compact version of "show all"
for showBoard, _ := range boards {
print( showBoard )
}
case "task": case "task":
// can check if a board is present with _, prs := // can check if a board is present with _, prs :=
// but this is a flag to be set if a task exists // but this is a flag to be set if a task exists
@@ -1492,6 +1508,16 @@ func show( search query ) {
help( showFailure ) help( showFailure )
return return
} }
case "tasks":
// compact version of showing all boards and their tasks
// no subtasks tho, thats just show all
// doesn't print any fills or anything like that, simple
for showBoard, contents := range boards {
print( showBoard )
for _, showTask := range contents {
print( "\t" + showTask.name )
}
}
case "subtask": case "subtask":
// can check if a board is present with _, prs := // can check if a board is present with _, prs :=
// but this is a flag to be set if a task exists // but this is a flag to be set if a task exists
@@ -1584,13 +1610,21 @@ type task struct {
var boards = make( map[string][]task ) var boards = make( map[string][]task )
var tasks []task // array of tasks referenced above var tasks []task // array of tasks referenced above
var subtasks []subtask // array of subtasks belonging to tasks var subtasks []subtask // array of subtasks belonging to tasks
var home string // declare string to keep track of home dir
// MAIN // MAIN
func main() { func main() {
// get home directory from user
home, err := dir()
if err != nil { // check if home dir failed
panic( err ) // panic if so
}
catch() // call function to catch keyboard interrupts catch() // call function to catch keyboard interrupts
fileIn() // open data file, process into structure fileIn( home ) // open data file, process into structure
for { // infinite loop, where everything happens for { // infinite loop, where everything happens
@@ -1637,7 +1671,7 @@ func main() {
case "mark": case "mark":
mark( search ) mark( search )
case "save": case "save":
fileOut() fileOut( home )
changed = false changed = false
print( "Updates saved" ) print( "Updates saved" )
case "show": case "show":
@@ -1651,7 +1685,7 @@ func main() {
// if file was changed, rewrite to file // if file was changed, rewrite to file
if changed { if changed {
fileOut() fileOut( home )
} }
exit( 0 ) // exeunt exit( 0 ) // exeunt
@@ -1670,7 +1704,7 @@ func main() {
if cmd { if cmd {
// if file was changed, rewrite to file // if file was changed, rewrite to file
if changed { if changed {
fileOut() fileOut( home )
} }
break break
} }