diff --git a/Gopkg.lock b/Gopkg.lock index 3610d97..7deee26 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -94,6 +94,12 @@ revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" version = "v1.1.0" +[[projects]] + branch = "master" + name = "github.com/pkg/browser" + packages = ["."] + revision = "c90ca0c84f15f81c982e32665bffd8d7aac8f097" + [[projects]] name = "github.com/pkg/errors" packages = ["."] @@ -182,6 +188,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "6dda3b48bf7ca07b2ae298ba7efe76169ff35927f9c6e3c8ea7db1c9fab9b59c" + inputs-digest = "418893d32e0530eb5af004dc03295e0b4d5410067a5d696b71790416a8c6637c" solver-name = "gps-cdcl" solver-version = 1 diff --git a/README.md b/README.md index 0dcc7da..f45e6ff 100644 --- a/README.md +++ b/README.md @@ -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| \ No newline at end of file diff --git a/persistence/mysqldriver/mysql.go b/persistence/mysqldriver/mysql.go index 40bb02f..15cd6b7 100644 --- a/persistence/mysqldriver/mysql.go +++ b/persistence/mysqldriver/mysql.go @@ -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 +} diff --git a/persistence/storage_persistor.go b/persistence/storage_persistor.go index 2ddf553..18ba40b 100644 --- a/persistence/storage_persistor.go +++ b/persistence/storage_persistor.go @@ -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) } diff --git a/persistence/toggldriver/toggl.go b/persistence/toggldriver/toggl.go index 776168b..3c1ced4 100644 --- a/persistence/toggldriver/toggl.go +++ b/persistence/toggldriver/toggl.go @@ -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 +} diff --git a/timenote/cmd/browser.go b/timenote/cmd/browser.go new file mode 100644 index 0000000..f556c8c --- /dev/null +++ b/timenote/cmd/browser.go @@ -0,0 +1,64 @@ +// Copyright © 2018 Sascha Andres +// +// 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) +} diff --git a/timenote/cmd/execute.go b/timenote/cmd/execute.go index 03804e1..8dd98a8 100644 --- a/timenote/cmd/execute.go +++ b/timenote/cmd/execute.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/mgutz/str" + "github.com/pkg/browser" "github.com/sascha-andres/timenote/persistence" ) @@ -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 }