Refactored output
This commit is contained in:
parent
5ab14a2467
commit
398460201e
6 changed files with 34 additions and 27 deletions
|
@ -35,7 +35,7 @@ func InitDatabase() (*Database, error) {
|
||||||
func (database *Database) NewID() (string) {
|
func (database *Database) NewID() (string) {
|
||||||
id, err := uuid.NewRandom()
|
id, err := uuid.NewRandom()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Could not generate UUID: %+v", err)
|
log.Fatalln("could not generate UUID: %+v", err)
|
||||||
}
|
}
|
||||||
return id.String()
|
return id.String()
|
||||||
}
|
}
|
||||||
|
@ -91,11 +91,11 @@ func (database *Database) FinishEntry(user string, entry Entry) (string, error)
|
||||||
dberr := database.DB.Update(func(tx *buntdb.Tx) error {
|
dberr := database.DB.Update(func(tx *buntdb.Tx) error {
|
||||||
runningEntryId, grerr := tx.Get(user + ":status:running")
|
runningEntryId, grerr := tx.Get(user + ":status:running")
|
||||||
if grerr != nil {
|
if grerr != nil {
|
||||||
return errors.New("No currently running entry found!")
|
return errors.New("no currently running entry found!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if runningEntryId != entry.ID {
|
if runningEntryId != entry.ID {
|
||||||
return errors.New("Specified entry is not currently running!")
|
return errors.New("specified entry is not currently running!")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, srerr := tx.Set(user + ":status:running", "", nil)
|
_, _, srerr := tx.Set(user + ":status:running", "", nil)
|
||||||
|
|
16
z/entry.go
16
z/entry.go
|
@ -103,14 +103,14 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.Task != "" && entry.Project != "" {
|
if entry.Task != "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("▷ %s %s on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
return fmt.Sprintf("%s %s %s on %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
} else if entry.Task != "" && entry.Project == "" {
|
} else if entry.Task != "" && entry.Project == "" {
|
||||||
return fmt.Sprintf("▷ %s %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), outputSuffix)
|
return fmt.Sprintf("%s %s %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Task), outputSuffix)
|
||||||
} else if entry.Task == "" && entry.Project != "" {
|
} else if entry.Task == "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("▷ %s task on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Project), outputSuffix)
|
return fmt.Sprintf("%s %s task on %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("▷ %s task%s\n", outputPrefix, outputSuffix)
|
return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) GetOutputForFinish() (string) {
|
func (entry *Entry) GetOutputForFinish() (string) {
|
||||||
|
@ -122,12 +122,12 @@ func (entry *Entry) GetOutputForFinish() (string) {
|
||||||
outputSuffix = fmt.Sprintf(" for %sh", color.FgLightWhite.Render(trackDiffOut.Format("15:04")))
|
outputSuffix = fmt.Sprintf(" for %sh", color.FgLightWhite.Render(trackDiffOut.Format("15:04")))
|
||||||
|
|
||||||
if entry.Task != "" && entry.Project != "" {
|
if entry.Task != "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("□ finished tracking %s on %s%s\n", color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
return fmt.Sprintf("%s finished tracking %s on %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
} else if entry.Task != "" && entry.Project == "" {
|
} else if entry.Task != "" && entry.Project == "" {
|
||||||
return fmt.Sprintf("□ finished tracking %s%s\n", color.FgLightWhite.Render(entry.Task), outputSuffix)
|
return fmt.Sprintf("%s finished tracking %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Task), outputSuffix)
|
||||||
} else if entry.Task == "" && entry.Project != "" {
|
} else if entry.Task == "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("□ finished tracking task on %s%s\n", color.FgLightWhite.Render(entry.Project), outputSuffix)
|
return fmt.Sprintf("%s finished tracking task on %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("□ finished tracking task%s\n", outputSuffix)
|
return fmt.Sprintf("%s finished tracking task%s\n", CharFinish, outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
12
z/finish.go
12
z/finish.go
|
@ -16,24 +16,24 @@ var finishCmd = &cobra.Command{
|
||||||
|
|
||||||
runningEntryId, err := database.GetRunningEntryId(user)
|
runningEntryId, err := database.GetRunningEntryId(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runningEntryId == "" {
|
if runningEntryId == "" {
|
||||||
fmt.Printf("□ not running\n")
|
fmt.Printf("%s not running\n", CharFinish)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
runningEntry, err := database.GetEntry(user, runningEntryId)
|
runningEntry, err := database.GetEntry(user, runningEntryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpEntry, err := NewEntry(runningEntry.ID, begin, finish, project, task, user)
|
tmpEntry, err := NewEntry(runningEntry.ID, begin, finish, project, task, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ var finishCmd = &cobra.Command{
|
||||||
|
|
||||||
_, err = database.FinishEntry(user, runningEntry)
|
_, err = database.FinishEntry(user, runningEntry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ func init() {
|
||||||
var err error
|
var err error
|
||||||
database, err = InitDatabase()
|
database, err = InitDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,13 @@ var task string
|
||||||
|
|
||||||
var force bool
|
var force bool
|
||||||
|
|
||||||
|
const(
|
||||||
|
CharTrack = "▶"
|
||||||
|
CharFinish = "■"
|
||||||
|
CharErase = "◀"
|
||||||
|
CharError = "▲"
|
||||||
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "zeit",
|
Use: "zeit",
|
||||||
Short: "Command line Zeiterfassung",
|
Short: "Command line Zeiterfassung",
|
||||||
|
@ -23,7 +30,7 @@ var rootCmd = &cobra.Command{
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
z/track.go
10
z/track.go
|
@ -15,18 +15,18 @@ var trackCmd = &cobra.Command{
|
||||||
|
|
||||||
runningEntryId, err := database.GetRunningEntryId(user)
|
runningEntryId, err := database.GetRunningEntryId(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runningEntryId != "" {
|
if runningEntryId != "" {
|
||||||
fmt.Printf("▷ a task is already running\n")
|
fmt.Printf("%s a task is already running\n", CharTrack)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
newEntry, err := NewEntry("", begin, finish, project, task, user)
|
newEntry, err := NewEntry("", begin, finish, project, task, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ var trackCmd = &cobra.Command{
|
||||||
|
|
||||||
_, err = database.AddEntry(user, newEntry, isRunning)
|
_, err = database.AddEntry(user, newEntry, isRunning)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func init() {
|
||||||
var err error
|
var err error
|
||||||
database, err = InitDatabase()
|
database, err = InitDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,18 @@ var trackingCmd = &cobra.Command{
|
||||||
|
|
||||||
runningEntryId, err := database.GetRunningEntryId(user)
|
runningEntryId, err := database.GetRunningEntryId(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runningEntryId == "" {
|
if runningEntryId == "" {
|
||||||
fmt.Printf("□ not running\n")
|
fmt.Printf("%s not running\n", CharFinish)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
runningEntry, err := database.GetEntry(user, runningEntryId)
|
runningEntry, err := database.GetEntry(user, runningEntryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func init() {
|
||||||
var err error
|
var err error
|
||||||
database, err = InitDatabase()
|
database, err = InitDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("△ %+v\n", err)
|
fmt.Printf("%s %+v\n", CharError, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue