Skip to content

Commit

Permalink
Merge branch 'main' of github.com:fantasticrabbit/ClickupCLI into get…
Browse files Browse the repository at this point in the history
…-list
  • Loading branch information
fantasticrabbit committed Nov 14, 2021
2 parents a9f7b0e + 044e921 commit 8f451e6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export CLICKUP_CLIENT_SECRET=xxx
export CLICKUP_PORT=9999
```

## SET command
### SET command

1. You can optionally set the local host port with the set command:
```
Expand All @@ -22,6 +22,8 @@ clickup set --team=1234567
```
1. Both parameters can be set in the same command, or provided as environment variables with the "CLICKUP_" prefix.

1. You can additionally set the token manually (--token), to use a personal token or for environments without a browser

## Usage

### Authentication
Expand Down
7 changes: 6 additions & 1 deletion cmd/gettask.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"errors"
"fmt"
"log"
"strings"

"github.com/fantasticrabbit/ClickupCLI/internal"
Expand Down Expand Up @@ -33,7 +34,11 @@ var taskCmd = &cobra.Command{
TeamID: viper.GetString("team"),
Subtasks: viper.GetBool("subtasks"),
}
fmt.Println(string(t.GetJSON(t.BuildPath())))
x, err := internal.FormatJSON(string(t.GetJSON(t.BuildPath())))
if err != nil {
log.Fatalln(err)
}
fmt.Println(x, err)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var logoutCmd = &cobra.Command{
Long: `logout allows the user to delete the access token for accessing a Clickup workspace`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("deleted authentication token")
viper.Set("ctoken", "")
viper.Set("token", "")
viper.WriteConfigAs(config_file)
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func initConfig() {
}

func checkToken() {
if !viper.InConfig("ctoken") || viper.GetString("ctoken") == "" {
if !viper.InConfig("token") || viper.GetString("token") == "" {
token, err := internal.GetToken()
if err != nil {
log.Fatalln("auth failed")
}
viper.Set("cToken", token)
viper.Set("Token", token)
viper.WriteConfigAs(config_file)
}
}
3 changes: 2 additions & 1 deletion cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var setCmd = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
keys := []string{"team", "port"}
keys := []string{"team", "port", "token"}
for _, key := range keys {
x, _ := cmd.Flags().GetString(key)
if x != "" {
Expand All @@ -37,4 +37,5 @@ func init() {
rootCmd.AddCommand(setCmd)
setCmd.Flags().StringP("team", "", "", "set the Team ID")
setCmd.Flags().StringP("port", "", "", "set the Redirect URL Port number")
setCmd.Flags().StringP("token", "", "", "set the Auth Token manually")
}
14 changes: 11 additions & 3 deletions internal/requester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internal

import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -29,10 +31,8 @@ func init() {

//Gets JSON data for any struct that implements Requester interface
func getJSON(apiPath string) []byte {
token := viper.GetString("ctoken")
req, _ := http.NewRequest(http.MethodGet, apiPath, nil)

req.Header.Add("Authorization", token)
req.Header.Add("Authorization", viper.GetString("token"))
req.Header.Add("Content-Type", "application/json")
resp, err := Client.Do(req)
if err != nil {
Expand All @@ -42,3 +42,11 @@ func getJSON(apiPath string) []byte {
resp_body, _ := ioutil.ReadAll(resp.Body)
return resp_body
}

func FormatJSON(str string) (string, error) {
var formattedJSON bytes.Buffer
if err := json.Indent(&formattedJSON, []byte(str), "", " "); err != nil {
return "", err
}
return formattedJSON.String(), nil
}

0 comments on commit 8f451e6

Please sign in to comment.