Skip to content

Commit

Permalink
merge: branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-andres committed May 17, 2018
2 parents c404ad3 + 4ca78ae commit 4296471
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ https://github.com/golang/dep

|Version|Description|
|---|---|
|TBD|Add cli|
|0.3.0|Add cli|
||Open in browser|
|0.2.0|Add projects|
|0.1.0|Initial version|
|0.2.0|Add support for projects|
4 changes: 4 additions & 0 deletions persistence/mysqldriver/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,7 @@ func (mysql *MySQLPersistor) getProjectID(name string) (int, error) {
}
return id, nil
}

func (mysql *MySQLPersistor) GetWebsite() (bool, string, error) {
return false, "", nil
}
2 changes: 2 additions & 0 deletions persistence/storage_persistor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ type Persistor interface {
// ListForDay(delta int) ([]timenote.TimeEntry, error)
// Get currently running time entry
Current() (*timenote.TimeEntry, error)
// GetWebsite returns a URL to the time management system
GetWebsite() (bool, string, error)
}
4 changes: 4 additions & 0 deletions persistence/toggldriver/toggl.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,7 @@ func (t *TogglPersistor) getProjectID(name string) (int, error) {

return 0, nil
}

func (t *TogglPersistor) GetWebsite() (bool, string, error) {
return true, "https://toggl.com/app/timer", nil
}
64 changes: 64 additions & 0 deletions timenote/cmd/browser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright © 2018 Sascha Andres <sascha.andres@outlook.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"

"github.com/pkg/browser"
"github.com/sascha-andres/timenote/persistence/factory"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// browserCmd represents the browser command
var browserCmd = &cobra.Command{
Use: "browser",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
persistence, err := factory.CreatePersistence(viper.GetString("persistor"), viper.GetString("dsn"))
if err != nil {
log.Fatal(err)
}
defer func() {
err := persistence.Close()
if err != nil {
log.Fatal(err)
}
}()

has, url, err := persistence.GetWebsite()
if err != nil {
log.Error(err)
return
}
if has {
browser.OpenURL(url)
} else {
fmt.Println("no url for backend")
}
},
}

func init() {
RootCmd.AddCommand(browserCmd)
}
10 changes: 10 additions & 0 deletions timenote/cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/mgutz/str"
"github.com/pkg/browser"
"github.com/sascha-andres/timenote/persistence"
)

Expand Down Expand Up @@ -36,6 +37,15 @@ func executeLine(persistence persistence.Persistor, commandline string) error {
case "tag":
return persistence.Tag(strings.Join(tokenize[1:], " "))
break
case "open":
hasOne, url, err := persistence.GetWebsite()
if err != nil {
return err
}
if hasOne {
return browser.OpenURL(url)
}
break
}
return nil
}

0 comments on commit 4296471

Please sign in to comment.