summaryrefslogtreecommitdiff
path: root/interact.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-10-19 12:30:46 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-10-19 12:30:46 +0200
commit404386194b9492b29b03d4e1e65558c545a70b51 (patch)
tree159b8f61939d7163ba4d63c2cd89ecda4579b1b7 /interact.go
parentae396b0399a9ee4ec8aee4879f0eb36bc7aeb7e8 (diff)
Trys in Auto-Documentation
Diffstat (limited to 'interact.go')
-rw-r--r--interact.go1399
1 files changed, 700 insertions, 699 deletions
diff --git a/interact.go b/interact.go
index 136e1d2..14e591f 100644
--- a/interact.go
+++ b/interact.go
@@ -1,727 +1,728 @@
package main
import (
- //"os"
- "strings"
- "strconv"
- "fmt"
- "time"
-
- //"github.com/abiosoft/ishell"
- "github.com/EPRparadox82/ishell"
- "github.com/fatih/color"
+ //"os"
+ "fmt"
+ "strconv"
+ "strings"
+ "time"
+
+ //"github.com/abiosoft/ishell"
+ "github.com/EPRparadox82/ishell"
+ "github.com/fatih/color"
)
-
func interact() {
- //stdOut()
- shell := ishell.New()
- shell.SetMultiChoicePrompt(" ->"," - ")
- shell.SetChecklistOptions("[ ] ","[X] ")
-
- //fmt.Println(os.Args)
- //cyan := color.New(color.FgCyan).SprintFunc()
- //yellow := color.New(color.FgYellow).SprintFunc()
- green := color.New(color.FgGreen).SprintFunc()
- boldBlue := color.New(color.FgBlue, color.Bold).SprintFunc()
- boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- boldMag := color.New(color.FgMagenta, color.Bold).SprintFunc()
- boldCyan := color.New(color.FgCyan, color.Bold).SprintFunc()
- boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
- boldYell := color.New(color.FgYellow, color.Bold).SprintFunc()
-
- promptcol := boldBlue
-
- // display info.
- //shell.Println("Starting interactive Shell")
- shell.SetPrompt(promptcol(">>>"))
-
- shell.AddCmd(&ishell.Cmd{
- Name: "new",
- Help: "Start new Project",
- LongHelp: ` Usage: new
+ //stdOut()
+ shell := ishell.New()
+ shell.SetMultiChoicePrompt(" ->", " - ")
+ shell.SetChecklistOptions("[ ] ", "[X] ")
+
+ //fmt.Println(os.Args)
+ //cyan := color.New(color.FgCyan).SprintFunc()
+ //yellow := color.New(color.FgYellow).SprintFunc()
+ green := color.New(color.FgGreen).SprintFunc()
+ boldBlue := color.New(color.FgBlue, color.Bold).SprintFunc()
+ boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
+ boldMag := color.New(color.FgMagenta, color.Bold).SprintFunc()
+ boldCyan := color.New(color.FgCyan, color.Bold).SprintFunc()
+ boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
+ boldYell := color.New(color.FgYellow, color.Bold).SprintFunc()
+
+ promptcol := boldBlue
+
+ // display info.
+ //shell.Println("Starting interactive Shell")
+ shell.SetPrompt(promptcol(">>>"))
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "new",
+ Help: "Start new Project",
+ LongHelp: ` Usage: new
If no Task is currently running a new project will be added to database and opened.
When there is an open Task the user will be notified to stop it before adding a new Project`,
- Func: func(c *ishell.Context) {
- //c.Print("\033[H\033[2J")
- //c.Println(boldGreen("Start New Project"))
- newProject()
- showLastProject()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "config",
- Help: "View and Edit Configuration",
- LongHelp: ` Usage: config
+ Func: func(c *ishell.Context) {
+ //c.Print("\033[H\033[2J")
+ //c.Println(boldGreen("Start New Project"))
+ newProject()
+ showLastProject()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "config",
+ Help: "View and Edit Configuration",
+ LongHelp: ` Usage: config
Show the current configuration and ask if it should be edited.
Configurations contains the location of the database file and the Personal Data needed for billing
If config is edited press <Enter> on empty line to keep the old entry`,
- Func: func(c *ishell.Context) {
- editConf()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "resume",
- Help: "Resume the Paused Task",
- LongHelp: ` Usage: resume
+ Func: func(c *ishell.Context) {
+ editConf()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "resume",
+ Help: "Resume the Paused Task",
+ LongHelp: ` Usage: resume
Resume the Task that was paused 'now'.`,
- Func: func(c *ishell.Context) {
- newTask(true)
- stdOut()
- setPauseTask(0)
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "pause",
- Help: "Close the Current Task and remember it",
- LongHelp: ` Usage: pause
+ Func: func(c *ishell.Context) {
+ newTask(true)
+ stdOut()
+ setPauseTask(0)
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "pause",
+ Help: "Close the Current Task and remember it",
+ LongHelp: ` Usage: pause
Closes the current task 'now' and remember it to continue later.
The User is not asked to enter a comment.`,
- Func: func(c *ishell.Context) {
- if opentask.id>0 {
- setPauseTask(opentask.id)
- c.Println("Pausing Task",pausetask)
- }
- closeTask(false)
- stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "status",
- Help: "Show Current Project and Tasks",
- LongHelp: ` Usage: status
+ Func: func(c *ishell.Context) {
+ if opentask.id > 0 {
+ setPauseTask(opentask.id)
+ c.Println("Pausing Task", pausetask)
+ }
+ closeTask(false)
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "status",
+ Help: "Show Current Project and Tasks",
+ LongHelp: ` Usage: status
Shows the current Project, its last Tasks and if there is a open Task.`,
- Func: func(c *ishell.Context) {
- stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "add",
- Help: "Add new Customer",
- LongHelp: ` Usage: add
+ Func: func(c *ishell.Context) {
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "add",
+ Help: "Add new Customer",
+ LongHelp: ` Usage: add
Add a new Customer to Database`,
- Func: func(c *ishell.Context) {
- addCustomer()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "startnow",
- Help: "Start a new Task immediately",
- LongHelp: ` Usage: startnow
+ Func: func(c *ishell.Context) {
+ addCustomer()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "startnow",
+ Help: "Start a new Task immediately",
+ LongHelp: ` Usage: startnow
Start a new Task in the currently open Project with current local time`,
- Func: func(c *ishell.Context) {
- newTask(false)
- stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "stopnow",
- Help: "Stop the currently Open Task immediately",
- LongHelp: ` Usage: stopnow
+ Func: func(c *ishell.Context) {
+ newTask(false)
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "stopnow",
+ Help: "Stop the currently Open Task immediately",
+ LongHelp: ` Usage: stopnow
Stop the open Task at the current local time.
If no task is open the user will be notified.`,
- Func: func(c *ishell.Context) {
- closeTask(true)
- stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "checkbill",
- Help: "<id> check a Bill with the following id as paid",
- LongHelp: ` Usage: checkbill <id>
+ Func: func(c *ishell.Context) {
+ closeTask(true)
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "checkbill",
+ Help: "<id> check a Bill with the following id as paid",
+ LongHelp: ` Usage: checkbill <id>
Check the bill of the set <id> as paid on the current date`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- checkBill(argi)
- //stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- c.Println(boldRed("checkbill <id> - Please enter an id"))
- showLastBills(0)
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "deletebill",
- Help: "<id> Delete a Bill with the following id",
- LongHelp: ` Usage: deletebill <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ checkBill(argi)
+ //stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ c.Println(boldRed("checkbill <id> - Please enter an id"))
+ showLastBills(0)
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "deletebill",
+ Help: "<id> Delete a Bill with the following id",
+ LongHelp: ` Usage: deletebill <id>
Delete the bill of the set <id> and set its Task back to unbilled`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- deleteBill(argi)
- stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- c.Println(boldRed("deletebill <id> - Please enter an id"))
- showLastBills(0)
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "deletetask",
- Help: "<id> Delete a Task with the following id",
- LongHelp: ` Usage: deletetask <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ deleteBill(argi)
+ stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ c.Println(boldRed("deletebill <id> - Please enter an id"))
+ showLastBills(0)
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "deletetask",
+ Help: "<id> Delete a Task with the following id",
+ LongHelp: ` Usage: deletetask <id>
Delete the Task of the set <id>`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- deleteTask(argi)
- stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- tids := getTaskIds()
- selids,lids := getTaskList(tids,false)
- choice := c.MultiChoice(lids,"Select a Task to Edit")
- if choice > -1 {
- deleteTask(selids[choice])
- }
- //c.Println(boldRed("deletetask <id> - Please enter an id"))
- //allProjects()
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "project",
- Help: "<id> Open a Project of the following id",
- LongHelp: ` Usage: project <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ deleteTask(argi)
+ stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ tids := getTaskIds()
+ selids, lids := getTaskList(tids, false)
+ choice := c.MultiChoice(lids, "Select a Task to Edit")
+ if choice > -1 {
+ deleteTask(selids[choice])
+ }
+ //c.Println(boldRed("deletetask <id> - Please enter an id"))
+ //allProjects()
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "project",
+ Help: "<id> Open a Project of the following id",
+ LongHelp: ` Usage: project <id>
Open the Project with the set <id>
If there is an open Task the user will be notified to close it first.`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- setProject(argi)
- stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- pids := getProjectIds()
- selids,lids := getProjectList(pids)
- choice := c.MultiChoice(lids,"Select a Project to Edit")
- if choice > -1 {
- setProject(selids[choice])
- }
- //c.Println(boldRed("editproject <id> - Please enter an id"))
- //c.Println(boldRed("project <id> - Please enter an id"))
- //allProjects()
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "edittask",
- Help: "<id> Edit a Task of the following id",
- LongHelp: ` Usage: edittask <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ setProject(argi)
+ stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ pids := getProjectIds()
+ selids, lids := getProjectList(pids)
+ choice := c.MultiChoice(lids, "Select a Project to Edit")
+ if choice > -1 {
+ setProject(selids[choice])
+ }
+ //c.Println(boldRed("editproject <id> - Please enter an id"))
+ //c.Println(boldRed("project <id> - Please enter an id"))
+ //allProjects()
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "edittask",
+ Help: "<id> Edit a Task of the following id",
+ LongHelp: ` Usage: edittask <id>
Edit Task of the set <id>.
Press <Enter> on empty line to keep the old entry`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- editTask(argi)
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- tids := getTaskIds()
- selids,lids := getTaskList(tids,false)
- choice := c.MultiChoice(lids,"Select a Task to Edit")
- //c.Println(tids)
- //c.Println(selids)
- if choice > -1 {
- editTask(selids[choice])
- //c.Println(choice,selids[choice])
- }
- //c.Println(boldRed("edittask <id> - Please enter an id"))
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "editproject",
- Help: "<id> Edit the Project of the following id",
- LongHelp: ` Usage: editproject <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ editTask(argi)
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ tids := getTaskIds()
+ selids, lids := getTaskList(tids, false)
+ choice := c.MultiChoice(lids, "Select a Task to Edit")
+ //c.Println(tids)
+ //c.Println(selids)
+ if choice > -1 {
+ editTask(selids[choice])
+ //c.Println(choice,selids[choice])
+ }
+ //c.Println(boldRed("edittask <id> - Please enter an id"))
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "editproject",
+ Help: "<id> Edit the Project of the following id",
+ LongHelp: ` Usage: editproject <id>
Edit Project of the set <id>.
Press <Enter> on empty line to keep the old entry`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- editProject(argi)
- //allProjects()
- //stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- pids := getProjectIds()
- selids,lids := getProjectList(pids)
- choice := c.MultiChoice(lids,"Select a Project to Edit")
- //c.Println(pids)
- //c.Println(selids)
- if choice > -1 {
- editProject(selids[choice])
- //c.Println(choice,selids[choice])
- }
- //c.Println(boldRed("editproject <id> - Please enter an id"))
- //allProjects()
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "editcustomer",
- Help: "<id> Edit the Customer of the following id",
- LongHelp: ` Usage: editcustomer <id>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ editProject(argi)
+ //allProjects()
+ //stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ pids := getProjectIds()
+ selids, lids := getProjectList(pids)
+ choice := c.MultiChoice(lids, "Select a Project to Edit")
+ //c.Println(pids)
+ //c.Println(selids)
+ if choice > -1 {
+ editProject(selids[choice])
+ //c.Println(choice,selids[choice])
+ }
+ //c.Println(boldRed("editproject <id> - Please enter an id"))
+ //allProjects()
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "editcustomer",
+ Help: "<id> Edit the Customer of the following id",
+ LongHelp: ` Usage: editcustomer <id>
Edit Customer of the set <id>.
Press <Enter> on empty line to keep the old entry`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- editCustomer(argi)
- allCustomers()
- //stdOut()
- }else{
- c.Println(boldRed(arg,"is not a valid id!"))
- }
- }else{
- selids,lids := getCustomerList()
- choice := c.MultiChoice(lids,"Select a Customer to Edit")
- if choice > -1 {
- editCustomer(selids[choice])
- }
- //c.Println(boldRed("editcustomer <id> - Please enter an id"))
- //allCustomers()
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "start",
- Help: "<DateTime> - Start Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'",
- LongHelp: ` Usage: start <DateTime>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ editCustomer(argi)
+ allCustomers()
+ //stdOut()
+ } else {
+ c.Println(boldRed(arg, "is not a valid id!"))
+ }
+ } else {
+ selids, lids := getCustomerList()
+ choice := c.MultiChoice(lids, "Select a Customer to Edit")
+ if choice > -1 {
+ editCustomer(selids[choice])
+ }
+ //c.Println(boldRed("editcustomer <id> - Please enter an id"))
+ //allCustomers()
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "start",
+ Help: "<DateTime> - Start Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'",
+ LongHelp: ` Usage: start <DateTime>
Start a new Task in the currently open Project at <DateTime>.
Use Format "YYYY-MM-DD HH:MM" or "HH:MM" for datetime.
If the latter is used the current local Date will be set.`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- newTaskTime(currproject.id,arg)
- stdOut()
- }else{
- c.Println(boldRed("start <DateTime> - Please enter a Datetime"))
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "stop",
- Help: "<DateTime> - Stop Open Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'",
- LongHelp: ` Usage: stop <DateTime>
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ newTaskTime(currproject.id, arg)
+ stdOut()
+ } else {
+ c.Println(boldRed("start <DateTime> - Please enter a Datetime"))
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "stop",
+ Help: "<DateTime> - Stop Open Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'",
+ LongHelp: ` Usage: stop <DateTime>
Stop the active Task at <DateTime>.
Use Format "YYYY-MM-DD HH:MM" or "HH:MM" for datetime.
If the latter is used the current local Date will be set.
In case of a Stop-time before Task start user will be notified.`,
- Func: func(c *ishell.Context) {
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- closeTaskTime(arg)
- stdOut()
- }else{
- c.Println(boldRed("stop <DateTime> - Please enter a Datetime"))
- }
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "all",
- Help: "Show all Projects",
- LongHelp: ` Usage: all
+ Func: func(c *ishell.Context) {
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ closeTaskTime(arg)
+ stdOut()
+ } else {
+ c.Println(boldRed("stop <DateTime> - Please enter a Datetime"))
+ }
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "all",
+ Help: "Show all Projects",
+ LongHelp: ` Usage: all
Show all Projects with small summary sorted by Customer.`,
- Func: func(c *ishell.Context) {
- allProjects()
- stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "allbills",
- Help: "Show all Bills",
- LongHelp: ` Usage: allbills
+ Func: func(c *ishell.Context) {
+ allProjects()
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "allbills",
+ Help: "Show all Bills",
+ LongHelp: ` Usage: allbills
Show all previous Bills with small summary.`,
- Func: func(c *ishell.Context) {
- showLastBills(0)
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "allcustomers",
- Help: "Show all Customers",
- LongHelp: ` Usage: allcustomers
+ Func: func(c *ishell.Context) {
+ showLastBills(0)
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "allcustomers",
+ Help: "Show all Customers",
+ LongHelp: ` Usage: allcustomers
Show all Customers.`,
- Func: func(c *ishell.Context) {
- allCustomers()
- c.Println(promptcol("______________________"))
- },
- })
-
- shell.AddCmd(&ishell.Cmd{
- Name: "showbills",
- Help: "<n> - Show the last n bills",
- LongHelp: ` Usage: showbills <n>
+ Func: func(c *ishell.Context) {
+ allCustomers()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "showbills",
+ Help: "<n> - Show the last n bills",
+ LongHelp: ` Usage: showbills <n>
Show the last n Bills with a small summary.`,
- Func: func(c *ishell.Context) {
- //c.ClearScreen()
- arg := "none"
- if len(c.Args) > 0 {
- arg = strings.Join(c.Args, " ")
- argi,err := strconv.Atoi(arg)
- if err == nil{
- showLastBills(argi)
- }else{
- c.Println(boldRed(arg,"is not a valid integer!"))
- }
- }else{
- c.Println(boldRed("showbills <n> - Please enter an integer"))
- }
- //stdOut()
- c.Println(promptcol("______________________"))
- },
- })
-/*
- // multiple choice
- shell.AddCmd(&ishell.Cmd{
- Name: "choice",
- Help: "multiple choice prompt",
- Func: func(c *ishell.Context) {
- choice := c.MultiChoice([]string{
- "Golangers",
- "Go programmers",
- "Gophers",
- "Goers",
- }, "What are Go programmers called ?")
- if choice == 2 {
- c.Println("You got it!")
- } else {
- c.Println("Sorry, you're wrong.")
- }
- },
- })
-
-// multiple choice
- shell.AddCmd(&ishell.Cmd{
- Name: "checklist",
- Help: "checklist prompt",
- Func: func(c *ishell.Context) {
- languages := []string{"Python", "Go", "Haskell", "Rust"}
- choices := c.Checklist(languages,
- "What are your favourite programming languages ?",
- nil)
- out := func() (c []string) {
- for _, v := range choices {
- c = append(c, languages[v])
- }
- return
- }
- c.Println("Your choices are", strings.Join(out(), ", "))
- },
- })
-*/
- //Test stuff in shell
- shell.AddCmd(&ishell.Cmd{
- Name: "test",
- Help: "Test some functions in interactive mode",
- LongHelp: ` Usage: test
+ Func: func(c *ishell.Context) {
+ //c.ClearScreen()
+ arg := "none"
+ if len(c.Args) > 0 {
+ arg = strings.Join(c.Args, " ")
+ argi, err := strconv.Atoi(arg)
+ if err == nil {
+ showLastBills(argi)
+ } else {
+ c.Println(boldRed(arg, "is not a valid integer!"))
+ }
+ } else {
+ c.Println(boldRed("showbills <n> - Please enter an integer"))
+ }
+ //stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+ /*
+ // multiple choice
+ shell.AddCmd(&ishell.Cmd{
+ Name: "choice",
+ Help: "multiple choice prompt",
+ Func: func(c *ishell.Context) {
+ choice := c.MultiChoice([]string{
+ "Golangers",
+ "Go programmers",
+ "Gophers",
+ "Goers",
+ }, "What are Go programmers called ?")
+ if choice == 2 {
+ c.Println("You got it!")
+ } else {
+ c.Println("Sorry, you're wrong.")
+ }
+ },
+ })
+
+ // multiple choice
+ shell.AddCmd(&ishell.Cmd{
+ Name: "checklist",
+ Help: "checklist prompt",
+ Func: func(c *ishell.Context) {
+ languages := []string{"Python", "Go", "Haskell", "Rust"}
+ choices := c.Checklist(languages,
+ "What are your favourite programming languages ?",
+ nil)
+ out := func() (c []string) {
+ for _, v := range choices {
+ c = append(c, languages[v])
+ }
+ return
+ }
+ c.Println("Your choices are", strings.Join(out(), ", "))
+ },
+ })
+ */
+ //Test stuff in shell
+ shell.AddCmd(&ishell.Cmd{
+ Name: "test",
+ Help: "Test some functions in interactive mode",
+ LongHelp: ` Usage: test
Test functions in interactive mode`,
- Func: func(c *ishell.Context) {
- multichoice("Geh scheissn")
+ Func: func(c *ishell.Context) {
+ multichoice("Geh scheissn")
- },
- })
+ },
+ })
- // Prompt Color
- shell.AddCmd(&ishell.Cmd{
- Name: "colorprompt",
- Help: "Select the Color of the prompt",
- LongHelp: ` Usage: colorprompt
+ // Prompt Color
+ shell.AddCmd(&ishell.Cmd{
+ Name: "colorprompt",
+ Help: "Select the Color of the prompt",
+ LongHelp: ` Usage: colorprompt
Select the color of the prompt`,
- Func: func(c *ishell.Context) {
- choice := c.MultiChoice([]string{
- boldMag("Magenta"),
- boldBlue("Blue"),
- boldCyan("Cyan"),
- boldGreen("Green"),
- boldYell("Yellow"),
- boldRed("Red"),
- }, "What Color should the Prompt be?")
- switch choice {
- case 0:
- c.SetPrompt(boldMag(">>>"))
- promptcol=boldMag
- case 1:
- c.SetPrompt(boldBlue(">>>"))
- promptcol=boldBlue
- case 2:
- c.SetPrompt(boldCyan(">>>"))
- promptcol=boldCyan
- case 3:
- c.SetPrompt(boldGreen(">>>"))
- promptcol=boldGreen
- case 4:
- c.SetPrompt(boldYell(">>>"))
- promptcol=boldYell
- case 5:
- c.SetPrompt(boldRed(">>>"))
- promptcol=boldRed
- }
- c.Println(promptcol("As You Wish!"))
-
- c.Println(promptcol("______________________"))
- },
- })
-// Gather Tasks For Bills
- shell.AddCmd(&ishell.Cmd{
- Name: "bill",
- Help: "Select Tasks to be billed",
- LongHelp: ` Usage: bill
+ Func: func(c *ishell.Context) {
+ choice := c.MultiChoice([]string{
+ boldMag("Magenta"),
+ boldBlue("Blue"),
+ boldCyan("Cyan"),
+ boldGreen("Green"),
+ boldYell("Yellow"),
+ boldRed("Red"),
+ }, "What Color should the Prompt be?")
+ switch choice {
+ case 0:
+ c.SetPrompt(boldMag(">>>"))
+ promptcol = boldMag
+ case 1:
+ c.SetPrompt(boldBlue(">>>"))
+ promptcol = boldBlue
+ case 2:
+ c.SetPrompt(boldCyan(">>>"))
+ promptcol = boldCyan
+ case 3:
+ c.SetPrompt(boldGreen(">>>"))
+ promptcol = boldGreen
+ case 4:
+ c.SetPrompt(boldYell(">>>"))
+ promptcol = boldYell
+ case 5:
+ c.SetPrompt(boldRed(">>>"))
+ promptcol = boldRed
+ }
+ c.Println(promptcol("As You Wish!"))
+
+ c.Println(promptcol("______________________"))
+ },
+ })
+ // Gather Tasks For Bills
+ shell.AddCmd(&ishell.Cmd{
+ Name: "bill",
+ Help: "Select Tasks to be billed",
+ LongHelp: ` Usage: bill
Select the tasks that should be merged into a Bill.
The Initial selection cannot be changed afterward. Only the complete
bill can be deleted and a new selection made.`,
- Func: func(c *ishell.Context) {
- nix := []int{0}
- ids,str := getTaskList(nix,true)
- choices := c.Checklist(str,
- "What Tasks do you want to bill ?",
- nil)
- out := func() (c []int) {
- for _, v := range choices {
- if v > -1 {
- c = append(c, ids[v])
- }
- }
- return
- }
- //All selected ids
- selids := out()
- //bids,str2 := getTaskList(selids,false)
- //c.Println(bids,str2)
- c.Println(len(selids),"Tasks Selected")
- //If None Selected end
- if len(selids) == 0 {
- return
- }
- //get if selected tasks have multicustomers, are from multipe projects, and get the ids of the projects
- multicust, multiproj,projids := checkCustomerProjects(selids)
- billprojid := 0
-
- // CHECK IF ONLY ONE CUSTOMER
- if multicust {
- c.Println(boldRed("Cannot Write One Bill to multiple Customers! Please Select different Tasks"))
-
- }else{
- // CHECK IF ONLY ONE PROJECT ELSE CHOOSE ONE
- if multiproj {
- prid,prstr :=getProjectList(projids)
- sel := c.MultiChoice(prstr, "What Project Should be Billed ?")
- if sel > -1 {
- billprojid = prid[sel]
- }
- }else{
- billprojid = projids[0]
- }
-
- seltasks := getSelectedTasks(selids)
- count,hours,dur := analyzeTasks(seltasks)
-
- //c.Printf("%v Tasks Selected. Totaling %.2f (h) - Dates: %s\n",count,hours,dur)
- proj,cust := getProject(billprojid)
- // IF CUSTOMER 0 NO BILL CAN BE CREATED
- if cust.id == 0 {
- c.Println(boldRed("Customer ",cust.company," with id ",cust.id," Cannot be billed. Please move ",proj.name," to a valid Customer"))
- return
- }
-
- //billid,billident := newBill(billprojid)
- //prs,cus := getProjectName(billprojid)
- //c.Println("For",cust.company,"-",cust.name)
- //c.Println("Project:",proj.name,"- ID:",proj.id)
- //c.Println("Projected Income:",hours*cust.satz,"€")
-
- //c.Println("Create New Bill:",billid)
- //c.ReadLine() //Make NEW BILL WITH ID and INV No
- c.ShowPrompt(false)
-
- //fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) - Invoice: %s Id:%v\nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n",cust.company,cust.name,cust.satz,billident,billid,proj.name,proj.id,count,hours,dur,hours*cust.satz)
- fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) \nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n",cust.company,cust.name,cust.satz,proj.name,proj.id,count,hours,dur,hours*cust.satz)
- sep := "-------------------------\n"
- restinfo := "Here some Info about the rest"
- restids := selids
- var allitems []billitem
-
- //allaccounted := false
- //resttasks := seltasks
- //SELECT SUBSET AND NAME BILLITEM
- //c.clear()//Println(some,"Str2:",str2)
- for {
- if len(restids) == 0 {
- break
- }
- resttasks := getSelectedTasks(restids)
- rcount,rhours,_ := analyzeTasks(resttasks)
-
- rids,rstr := getTaskList(restids,false)
- qu := "Select Tasks to Group as Billitem"
- restinfo = fmt.Sprintf("%v Tasks Left, Total %.2f(h)\n%s",rcount,rhours,qu)
- pre := fmt.Sprintf("%s%s%s",fullbillinfo,sep,restinfo)
-
- choices2 := c.Checklist(rstr,pre,nil)
- out = func() (c []int) {
- for _, v := range choices2 {
- if v > -1 {
- c = append(c, rids[v])
- }
+ Func: func(c *ishell.Context) {
+ nix := []int{0}
+ ids, str := getTaskList(nix, true)
+ choices := c.Checklist(str,
+ "What Tasks do you want to bill ?",
+ nil)
+ out := func() (c []int) {
+ for _, v := range choices {
+ if v > -1 {
+ c = append(c, ids[v])
+ }
+ }
+ return
+ }
+ //All selected ids
+ selids := out()
+ //bids,str2 := getTaskList(selids,false)
+ //c.Println(bids,str2)
+ c.Println(len(selids), "Tasks Selected")
+ //If None Selected end
+ if len(selids) == 0 {
+ return
}
- return
- }
- taskids := out()
- restids = removeItems(restids,taskids)
-
- if len(taskids)>0 {
- ittasks := getSelectedTasks(taskids)
- itcount,ithours,itdur := analyzeTasks(ittasks)
- c.Printf("\n%v Tasks Selected, Total %.2f(h), Date: %s\n",itcount,ithours,itdur)
- c.ShowPrompt(false)
- c.Print("Name your Task for the Bill: ")
- tsk := c.ReadLine()
- var hrf float64
- for {
- c.Print("How Many Hours: ")
- hr := c.ReadLine()
- hrf,err = strconv.ParseFloat(hr,64)
- if err != nil {
- c.Println(hr,boldRed("can not be Parsed as a Float."),"Try a shape of X.X")
- }else{break}
- }
- c.Printf("%T %v - %T %v\n",tsk,tsk,hrf,hrf)
- allitems = append(allitems,billitem{tsk,itdur,hrf,Round(hrf*cust.satz,5)})
- c.Print("<<Continue>>")
- c.ReadLine()
- //c.ShowPrompt(true)
- }
- }
- billid,billident := newBill(billprojid)
- c.Println(green("Bill Completed"))
- fullbill := bill{billid,billident,dur,proj.id,proj.name,time.Time{},time.Time{},allitems}
- saveBill(fullbill)
- checkTasks(selids,billid)
- c.ProgressBar().Indeterminate(true)
- c.ProgressBar().Start()
- testid := []int{billid}
- testbill := loadBills(testid)
- //c.Println(testbill[0].projectname,testbill[0].items)
- files := billTemplate(testbill[0],cust)
- c.Println(files)
- err = runLatex(files.Main,testbill[0].identity)
- c.ProgressBar().Stop()
- if err== nil {
- c.Println("Finished without Errors")
- }else{
- c.Println("Finished with error:",err)
- }
- c.Print("<<Continue>>")
- c.ReadLine()
- stdOut()
- }
- c.Println(promptcol("______________________"))
- c.ShowPrompt(true)
- },
- })
-
- // Decide if interactive mode should be started
- //args := removeStringFromArray(os.Args[1:],"-file",1)
-
- if len(interArgs) > 0 {
- //args := removeStringFromArray(os.Args[1:],"-file",1)
- //fmt.Println(args)
- shell.Process(interArgs...)
- } else {
- shell.Println("Starting interactive Shell")
- stdOut()
- //start shell
- shell.Run()
- // teardown
- shell.Close()
- }
- //fmt.Println("Laboravi emeritus...")
+ //get if selected tasks have multicustomers, are from multipe projects, and get the ids of the projects
+ multicust, multiproj, projids := checkCustomerProjects(selids)
+ billprojid := 0
+
+ // CHECK IF ONLY ONE CUSTOMER
+ if multicust {
+ c.Println(boldRed("Cannot Write One Bill to multiple Customers! Please Select different Tasks"))
+
+ } else {
+ // CHECK IF ONLY ONE PROJECT ELSE CHOOSE ONE
+ if multiproj {
+ prid, prstr := getProjectList(projids)
+ sel := c.MultiChoice(prstr, "What Project Should be Billed ?")
+ if sel > -1 {
+ billprojid = prid[sel]
+ }
+ } else {
+ billprojid = projids[0]
+ }
+
+ seltasks := getSelectedTasks(selids)
+ count, hours, dur := analyzeTasks(seltasks)
+
+ //c.Printf("%v Tasks Selected. Totaling %.2f (h) - Dates: %s\n",count,hours,dur)
+ proj, cust := getProject(billprojid)
+ // IF CUSTOMER 0 NO BILL CAN BE CREATED
+ if cust.id == 0 {
+ c.Println(boldRed("Customer ", cust.company, " with id ", cust.id, " Cannot be billed. Please move ", proj.name, " to a valid Customer"))
+ return
+ }
+
+ //billid,billident := newBill(billprojid)
+ //prs,cus := getProjectName(billprojid)
+ //c.Println("For",cust.company,"-",cust.name)
+ //c.Println("Project:",proj.name,"- ID:",proj.id)
+ //c.Println("Projected Income:",hours*cust.satz,"€")
+
+ //c.Println("Create New Bill:",billid)
+ //c.ReadLine() //Make NEW BILL WITH ID and INV No
+ c.ShowPrompt(false)
+
+ //fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) - Invoice: %s Id:%v\nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n",cust.company,cust.name,cust.satz,billident,billid,proj.name,proj.id,count,hours,dur,hours*cust.satz)
+ fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) \nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n", cust.company, cust.name, cust.satz, proj.name, proj.id, count, hours, dur, hours*cust.satz)
+ sep := "-------------------------\n"
+ restinfo := "Here some Info about the rest"
+ restids := selids
+ var allitems []billitem
+
+ //allaccounted := false
+ //resttasks := seltasks
+ //SELECT SUBSET AND NAME BILLITEM
+ //c.clear()//Println(some,"Str2:",str2)
+ for {
+ if len(restids) == 0 {
+ break
+ }
+ resttasks := getSelectedTasks(restids)
+ rcount, rhours, _ := analyzeTasks(resttasks)
+
+ rids, rstr := getTaskList(restids, false)
+ qu := "Select Tasks to Group as Billitem"
+ restinfo = fmt.Sprintf("%v Tasks Left, Total %.2f(h)\n%s", rcount, rhours, qu)
+ pre := fmt.Sprintf("%s%s%s", fullbillinfo, sep, restinfo)
+
+ choices2 := c.Checklist(rstr, pre, nil)
+ out = func() (c []int) {
+ for _, v := range choices2 {
+ if v > -1 {
+ c = append(c, rids[v])
+ }
+ }
+ return
+ }
+ taskids := out()
+ restids = removeItems(restids, taskids)
+
+ if len(taskids) > 0 {
+ ittasks := getSelectedTasks(taskids)
+ itcount, ithours, itdur := analyzeTasks(ittasks)
+ c.Printf("\n%v Tasks Selected, Total %.2f(h), Date: %s\n", itcount, ithours, itdur)
+ c.ShowPrompt(false)
+ c.Print("Name your Task for the Bill: ")
+ tsk := c.ReadLine()
+ var hrf float64
+ for {
+ c.Print("How Many Hours: ")
+ hr := c.ReadLine()
+ hrf, err = strconv.ParseFloat(hr, 64)
+ if err != nil {
+ c.Println(hr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X")
+ } else {
+ break
+ }
+ }
+ c.Printf("%T %v - %T %v\n", tsk, tsk, hrf, hrf)
+ allitems = append(allitems, billitem{tsk, itdur, hrf, Round(hrf*cust.satz, 5)})
+ c.Print("<<Continue>>")
+ c.ReadLine()
+ //c.ShowPrompt(true)
+ }
+ }
+ billid, billident := newBill(billprojid)
+ c.Println(green("Bill Completed"))
+ fullbill := bill{billid, billident, dur, proj.id, proj.name, time.Time{}, time.Time{}, allitems}
+ saveBill(fullbill)
+ checkTasks(selids, billid)
+ c.ProgressBar().Indeterminate(true)
+ c.ProgressBar().Start()
+ testid := []int{billid}
+ testbill := loadBills(testid)
+ //c.Println(testbill[0].projectname,testbill[0].items)
+ files := billTemplate(testbill[0], cust)
+ c.Println(files)
+ err = runLatex(files.Main, testbill[0].identity)
+ c.ProgressBar().Stop()
+ if err == nil {
+ c.Println("Finished without Errors")
+ } else {
+ c.Println("Finished with error:", err)
+ }
+ c.Print("<<Continue>>")
+ c.ReadLine()
+ stdOut()
+ }
+ c.Println(promptcol("______________________"))
+ c.ShowPrompt(true)
+ },
+ })
+
+ // Decide if interactive mode should be started
+ //args := removeStringFromArray(os.Args[1:],"-file",1)
+
+ if len(interArgs) > 0 {
+ //args := removeStringFromArray(os.Args[1:],"-file",1)
+ //fmt.Println(args)
+ shell.Process(interArgs...)
+ } else {
+ shell.Println("Starting interactive Shell")
+ stdOut()
+ //start shell
+ shell.Run()
+ // teardown
+ shell.Close()
+ }
+ //fmt.Println("Laboravi emeritus...")
}
-func isInterSure(question string) (bool) {
+func isInterSure(question string) bool {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
- shell.Printf("%s (type 'y/Y/yes' to confirm) : ",question)
+ shell.Printf("%s (type 'y/Y/yes' to confirm) : ", question)
line := shell.ReadLine()
- if ( line == "yes" || line == "y" || line == "Y") {
+ if line == "yes" || line == "y" || line == "Y" {
return true
} else {
return false
@@ -739,20 +740,20 @@ func getInterInput(question string) (out string) {
return
}
-func getNewInterInput(question,old string) (string) {
+func getNewInterInput(question, old string) string {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
if old != "" {
- shell.Println("Current:",old)
+ shell.Println("Current:", old)
}
shell.Print(question)
line := shell.ReadLine()
if line == "" {
return old
- }else{
+ } else {
return line
}
}
@@ -762,32 +763,32 @@ func getInterMultiInput(question string) (out string) {
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
- shell.Println(question,"(Multiline input, end with ';')")
+ shell.Println(question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
shell.Println(" -Done-")
return
}
-func getNewInterMultiInput(question,old string) (out string) {
+func getNewInterMultiInput(question, old string) (out string) {
shell := ishell.New()
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
if old != "" {
- shell.Println("Current:\n",old)
+ shell.Println("Current:\n", old)
}
shell.Println("Should current entry be replaced? A Newline will be added otherwise")
- if isInterSure(" "){
- shell.Println(question,"(Multiline input, end with ';')")
+ if isInterSure(" ") {
+ shell.Println(question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
shell.Println(" -Done-")
- }else{
+ } else {
shell.Print(question)
txt := shell.ReadLine()
if txt == "" {
out = old
- }else{
+ } else {
out = old + "\n" + txt
}
}
@@ -802,27 +803,27 @@ func getNewInterMultiInput(question,old string) (out string) {
func multichoice(about string) {
- shell := ishell.New()
- shell.SetMultiChoicePrompt(" ->"," - ")
- shell.SetChecklistOptions("[ ] ","[X] ")
-
- shell.AddCmd(&ishell.Cmd{
- Name: "choice",
- Help: "multiple choice prompt",
- Func: func(c *ishell.Context) {
- choice := c.MultiChoice([]string{
- "Golangers",
- "Go programmers",
- "Gophers",
- "Goers",
- }, "What are Go programmers called ?")
- if choice == 2 {
- c.Println("You got it!")
- } else {
- c.Println("Sorry, you're wrong.")
- }
- },
- })
+ shell := ishell.New()
+ shell.SetMultiChoicePrompt(" ->", " - ")
+ shell.SetChecklistOptions("[ ] ", "[X] ")
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "choice",
+ Help: "multiple choice prompt",
+ Func: func(c *ishell.Context) {
+ choice := c.MultiChoice([]string{
+ "Golangers",
+ "Go programmers",
+ "Gophers",
+ "Goers",
+ }, "What are Go programmers called ?")
+ if choice == 2 {
+ c.Println("You got it!")
+ } else {
+ c.Println("Sorry, you're wrong.")
+ }
+ },
+ })
str := "choice"
shell.Process(str)
shell.Println(about)