summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-09-15 03:31:52 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-09-15 03:31:52 +0200
commitb67ad525147b8d219ff3508674dec3b25a3f62f0 (patch)
tree2684d4bb2dce753a9d90b892735f45360e5413b0
parent4fa9a4e986d457b406236fc62a5955a2275b83a9 (diff)
Makefile added, everything streamlined0.2.10.2.0
-rw-r--r--interact.go26
-rw-r--r--main.go198
-rwxr-xr-xmakefile28
-rw-r--r--utils.go36
4 files changed, 109 insertions, 179 deletions
diff --git a/interact.go b/interact.go
index a18a7a8..31e93e6 100644
--- a/interact.go
+++ b/interact.go
@@ -1,7 +1,7 @@
package main
import (
- //"os"
+ "os"
"strings"
"strconv"
"fmt"
@@ -16,6 +16,7 @@ func interact() {
stdOut()
shell := ishell.New()
+ //fmt.Println(os.Args)
//cyan := color.New(color.FgCyan).SprintFunc()
//yellow := color.New(color.FgYellow).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
@@ -400,7 +401,7 @@ func interact() {
if multicust {
c.Println("Cannot Write One Bill to multiple Customers! Please Select different Tasks")
-
+
}else{
// CHECK IF ONLY ONE PROJECT ELSE CHOOSE ONE
if multiproj {
@@ -507,18 +508,21 @@ func interact() {
},
})
- shell.Run()
+ //shell.Run()
// teardown
- shell.Close()
+ //shell.Close()
// when started with "exit" as first argument, assume non-interact ive execution
- // if len(os.Args) > 1 && os.Args[1] == "exit" {
- // shell.Process(os.Args[2:]...)
- // } else {
- // start shell
- // shell.Run()
+
+ if len(os.Args) > 1 {
+ args := removeStringFromArray(os.Args[1:],"-file",1)
+ //fmt.Println(args)
+ shell.Process(args...)
+ } else {
+ //start shell
+ shell.Run()
// teardown
- // shell.Close()
- //}
+ shell.Close()
+ }
}
diff --git a/main.go b/main.go
index d74bde5..2974eb5 100644
--- a/main.go
+++ b/main.go
@@ -3,7 +3,7 @@ package main
import (
"fmt"
"flag"
- "path/filepath"
+ _ "path/filepath"
_ "log"
//"bufio"
"os"
@@ -12,11 +12,15 @@ import (
"github.com/fatih/color"
)
+var (
+ version string
+ compdate string
+)
//var svar string
-var starttime,stoptime string
-var projectid, edittaskid, editprojectid, editcustomerid int
-var deltask,delbill int
-var addcustomer bool
+var starttime,stoptime,filename string
+//var projectid, edittaskid, editprojectid, editcustomerid int
+//var deltask,delbill int
+//var addcustomer bool
var newproject, newtask, stoptask, allproj, allbills, runinter, test, newconfig bool
var billcount int
@@ -40,6 +44,7 @@ func title(frame bool) {
fmt.Println(" ",bR("L"),bHiR("A"),bHiY("B"),bHiG("O"),bHiC("R"),bHiB("A"),bHiM("V"),bM("I"))
if frame {
fmt.Printf("%s%s%s%s%s%s%s%s\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line))
+ fmt.Printf("Version %s (%s)\n",version,compdate)
fmt.Println("(c) 2018 - n@gotsche.at\n")
}
}
@@ -47,92 +52,20 @@ func title(frame bool) {
func init() {
- //red := color.New(color.FgRed).SprintFunc
- //green := color.New(color.FgGreen)
- //yellow := color.New(color.FgYellow)
- //use of package color without selectorcyan := color.New(color.FgCyan)
- //boldGreen := color.New(color.FgGreen, color.Bold)
- //boldRed := color.New(color.FgRed, color.Bold)
+
+ //flag.StringVar(&svar, "svar", "bar", "A String Var")
flag.BoolVar(&test,
"test",
false,
"Test Some Functions")
-
-
- flag.BoolVar(&newconfig,
- "config",
- false,
- "View and Edit Configuration")
- flag.BoolVar(&addcustomer,
- "add",
- false,
- "Adds a new Customer")
- flag.BoolVar(&allproj,
- "all",
- false,
- "Show all Projects")
- flag.BoolVar(&allbills,
- "allbills",
- false,
- "Show all Bills")
- flag.IntVar(&billcount,
- "showbills",
- 0,
- "How Many of Previous bills should be shown")
- flag.BoolVar(&runinter,
- "run",
- false,
- "Run in Interactive mode")
- flag.BoolVar(&newtask,
- "startnow",
- false,
- "Start a new Task in current project")
- flag.IntVar(&delbill,
- "deletebill",
- 0,
- "Specify which Bill to delete")
- flag.IntVar(&deltask,
- "deletetask",
- 0,
- "Specify which Task to delete")
- flag.IntVar(&edittaskid,
- "edittask",
- 0,
- "Specify which Task to edit")
- flag.IntVar(&editprojectid,
- "editproject",
- 0,
- "Specify which project to edit")
- flag.IntVar(&editcustomerid,
- "editcustomer",
- 0,
- "Specify which customer to edit")
- flag.IntVar(&projectid,
- "project",
- 0,
- "Specify which project to track")
- flag.BoolVar(&stoptask,
- "stopnow",
- false,
- "Stop the currently open task")
- flag.StringVar(&starttime,
- "start",
- "now",
- "Start a new Task in current project\nFormat: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
- flag.StringVar(&stoptime,
- "stop",
- "now",
- "Stop to Track the current Task\nFormat: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
- flag.BoolVar(&newproject,
- "new",
- false,
- "Create a new project")
- //flag.StringVar(&svar, "svar", "bar", "A String Var")
-
+ flag.StringVar(&filename,
+ "file",
+ "~/.mytimes.db",
+ "Open a different Database than specified in Configuration")
// CUSTOMIZE USAGE
flag.Usage = func() {
- fmt.Fprintf(os.Stderr, "Usage of %s Version 0.1.4:\n %s [Options] [Database]\n\n [Database] - must have .db fileextension, only one allowed\n\n [Options]:\n", os.Args[0],os.Args[0])
+ fmt.Fprintf(os.Stderr, "Usage of %s Version %s (%s):\n %s [Options] args\n\n Arguments: use 'help' to get the full list \n\n [Options]:\n", os.Args[0],version,compdate,os.Args[0])
flag.PrintDefaults()
}
@@ -149,18 +82,18 @@ func stdOut() {
}
func main() {
- boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
+ //boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
//fmt.Println("Laboravi Started")
dbname := "./.mytimes.db"
- if flag.NFlag() > 0 {
+// if flag.NFlag() > 0 {
title(true)
- }else{
- title(false)
+// }else{
+// title(false)
//fmt.Println("Laboravi Started")
- }
+// }
initConf()
dbname = config.Database
- if len(flag.Args())>0 {
+/* if len(flag.Args())>0 {
aar := flag.Args()
var uar []string
@@ -181,13 +114,10 @@ func main() {
fmt.Println("Unknown Commands: ",boldRed(uar))
}
}
-
- initDB(dbname)
- getLastProject()
- //getProjects()
- getOpenTask()
+*/
if test {
+ fmt.Println(getGitTag())
fmt.Println("Nothing to test")
//tmpltest()
//newBill(1)
@@ -197,79 +127,11 @@ func main() {
os.Exit(0)
}
- if allproj {
- allProjects()
- }
-
- if allbills {
- showLastBills(0)
- } else if (billcount>0) {
- showLastBills(billcount)
- }
+ initDB(dbname)
+ getLastProject()
+ //getProjects()
+ getOpenTask()
- if runinter {
- interact()
- }
- if newconfig {
- editConf()
- }
- if newproject {
- newProject()
- os.Exit(0)
- } else if addcustomer {
- addCustomer()
- os.Exit(0)
- } else if newtask {
- showLastProject()
- newTask(projectid)
- stdOut()
- //showLastProject()
- //getClosedTasks(0)
- //showOpenTask()
- //os.Exit(0)
- } else if stoptask {
- closeTask()
- stdOut()
- //showLastProject()
- //getClosedTasks(0)
- //showOpenTask()
- } else if (starttime != "now") {
- showLastProject()
- newTaskTime(projectid,starttime)
- os.Exit(0)
- } else if (stoptime != "now") {
- closeTaskTime(stoptime)
- stdOut()
- //showLastProject()
- //getClosedTasks(0)
- //showOpenTask()
- } else if (delbill>0) {
- deleteBill(delbill)
- } else if (deltask>0) {
- deleteTask(deltask)
- } else if (edittaskid>0) {
- editTask(edittaskid)
- } else if (editprojectid>0) {
- editProject(editprojectid)
- } else if (editcustomerid>0) {
- editCustomer(editcustomerid)
- } else if (projectid>0) {
- setProject(projectid)
- stdOut()
- //showLastProject()
- //getClosedTasks(0)
- //showOpenTask()
- } else {
- //showLastProject()
- //getClosedTasks(0)
- //showOpenTask()
- stdOut()
- }
+ interact()
- //fmt.Println("Start Act:",actstart)
- //fmt.Println("Stop Act:",actstop)
- //fmt.Println("Project:",projectid)
- //fmt.Println("New Project:",newproject)
- //fmt.Println("svar:",svar)
- //fmt.Println("Unknown Commands: ",flag.Args())
}
diff --git a/makefile b/makefile
new file mode 100755
index 0000000..dc9bb34
--- /dev/null
+++ b/makefile
@@ -0,0 +1,28 @@
+version=$(shell git tag --points-at)
+date=$(shell date "+%b %Y")
+name=laboravi
+.PHONY: all
+
+all:
+ @echo " make <cmd>"
+ @echo ""
+ @echo "Commands:"
+ @echo " build - runs go build with ldflags version=${version} & date=${date}"
+ @echo " fetch_stuff - installs all needed programs and libaries"
+ @echo ""
+
+
+build: clean
+ @go build -v -ldflags '-X "main.version=${version}" -X "main.compdate=${date}"' -o ${name}
+
+clean:
+ @rm -f ${name}
+
+fetch_stuff:
+ @sudo apt-get install sqlite3
+ @go get github.com/fatih/color
+ @go get github.com/mattn/go-sqlite3
+ @go get github.com/abiosoft/ishell
+ @mkdir outpdf
+ @mkdir outtex
+ @echo "All nessecary libaries installed"
diff --git a/utils.go b/utils.go
index ad9693d..1400d63 100644
--- a/utils.go
+++ b/utils.go
@@ -4,12 +4,48 @@ import (
"fmt"
"bufio"
"os"
+ "os/exec"
"math"
"strings"
"strconv"
"runtime"
)
+func getGitTag() string {
+ var (
+ cmdOut []byte
+ err error
+ )
+ cmd := "git"
+ args := []string{"tag","--points-at","HEAD"}
+ if cmdOut,err = exec.Command(cmd,args...).Output(); err != nil {
+ panic(err)
+ }
+ return string(cmdOut)
+}
+
+//Remove a string from a []string and the int number of strings afterwards
+func removeStringFromArray(arr []string,rem string,after int) (out []string) {
+ found := false
+ i := 0
+ for _,st := range arr {
+ if found {
+ if i < after {
+ i++
+ }else{
+ found = false
+ }
+ }else{
+ if st == rem {
+ found = true
+ }else{
+ out = append(out,st)
+ }
+ }
+ }
+ return
+}
+
func isSure(quest string) bool {
fmt.Printf("%s (type 'y/Y/yes' to confirm) : ",quest)
in := bufio.NewReader(os.Stdin)