Skip to content

Commit

Permalink
use flag for create new docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hirosassa committed Jun 27, 2021
1 parent c2de7c3 commit 31c2e72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 93 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,17 @@ $ biko googleworkspace [product] [flag(s)]
$ biko gw [product] [flag(s)]
```

| Product | What | Command | Flags(Optional) |
| :----: |:----:|:----:|:----:|
| Product | What | Command | Flags(Optional) |
| :----: | :----: | :----: | :----: |
| drive | Search on Google Drive | `drive`, `dr` | `--query, -q` |
| document | Search on Google Docs | `document`, `dc` | `--query, -q` |
| document | Create a new Google Docs | `document new`, `dc n` | - |
| document | Create a new Google Docs | `document`, `dc` | `--new, -n` |
| spreadsheets | Search on Google Sheets | `spreadsheets`, `ss` | `--query, -q` |
| spreadsheets | Create a new Google Sheets | `spreadsheets new`, `ss n` | - |
| spreadsheets | Create a new Google Sheets | `spreadsheets`, `ss` | `--new, -n` |
| presentation | Search on Google Slides | `presentation`, `pr` | `--query, -q` |
| presentation | Create a new Google Slides | `presentation new`, `pr new` | - |
| presentation | Create a new Google Slides | `presentation`, `pr` | `--new, -n` |
| forms | Search on Google Forms | `forms`, `fm` | `--query, -q` |
| forms | Create a new Google Forms | `forms new`, `fm n` | - |
| forms | Create a new Google Forms | `forms`, `fm` | `--new, -n` |


### Pagerduty
Expand Down
101 changes: 19 additions & 82 deletions cli/googleworkspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func newGoogleWorkspaceCmd() cli.Command {
Subcommands: []cli.Command{
newDriveCmd(),
newDocumentCmd(),
newSpreadsheetCmd(),
newSpreadsheetsCmd(),
newPresentationCmd(),
newFormsCmd(),
},
}
}
Expand Down Expand Up @@ -75,6 +76,10 @@ func newDocumentCmd() cli.Command {
Name: "query, q",
Usage: "Query a page",
},
cli.BoolFlag{
Name: "new, n",
Usage: "Create a new document (this flag prioritize over query flag)",
},
},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
Expand All @@ -83,14 +88,11 @@ func newDocumentCmd() cli.Command {
}
return browser.Open(c, g)
},
Subcommands: []cli.Command{
newNewDocumentCmd(),
},
}

}

func newSpreadsheetCmd() cli.Command {
func newSpreadsheetsCmd() cli.Command {
return cli.Command{
Name: "spreadsheets",
Aliases: []string{"ss"},
Expand All @@ -100,6 +102,10 @@ func newSpreadsheetCmd() cli.Command {
Name: "query, q",
Usage: "Query a page",
},
cli.BoolFlag{
Name: "new, n",
Usage: "Create a new spreadsheet (this flag prioritize over query flag)",
},
},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
Expand All @@ -108,9 +114,6 @@ func newSpreadsheetCmd() cli.Command {
}
return browser.Open(c, g)
},
Subcommands: []cli.Command{
newNewSpreadsheetCmd(),
},
}

}
Expand All @@ -125,6 +128,10 @@ func newPresentationCmd() cli.Command {
Name: "query, q",
Usage: "Query a page",
},
cli.BoolFlag{
Name: "new, n",
Usage: "Create a new presentation (this flag prioritize over query flag)",
},
},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
Expand All @@ -133,9 +140,6 @@ func newPresentationCmd() cli.Command {
}
return browser.Open(c, g)
},
Subcommands: []cli.Command{
newNewPresentationCmd(),
},
}

}
Expand All @@ -150,6 +154,10 @@ func newFormsCmd() cli.Command {
Name: "query, q",
Usage: "Query a page",
},
cli.BoolFlag{
Name: "new, n",
Usage: "Create a new form (this flag prioritize over query flag)",
},
},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
Expand All @@ -158,77 +166,6 @@ func newFormsCmd() cli.Command {
}
return browser.Open(c, g)
},
Subcommands: []cli.Command{
newNewFormsCmd(),
},
}

}

func newNewDocumentCmd() cli.Command {
return cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "Create a new document",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
if err != nil {
return err
}
return browser.Open(c, g)
},
}

}

func newNewSpreadsheetCmd() cli.Command {
return cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "Create a new spreadsheet",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
if err != nil {
return err
}
return browser.Open(c, g)
},
}

}

func newNewPresentationCmd() cli.Command {
return cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "Create a new presentation",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
if err != nil {
return err
}
return browser.Open(c, g)
},
}

}

func newNewFormsCmd() cli.Command {
return cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "Create a new form",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
g, err := googleworkspace.GetProvider()
if err != nil {
return err
}
return browser.Open(c, g)
},
}

}
10 changes: 5 additions & 5 deletions providers/googleworkspace/googleworkspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package googleworkspace
import (
"net/url"
"path"
"strings"

"github.com/KeisukeYamashita/biko/alias"
"github.com/urfave/cli"
Expand Down Expand Up @@ -59,12 +58,13 @@ func (p *Provider) Init(c *cli.Context) error {

// GetTargetURL ...
func (p *Provider) GetTargetURL() (string, error) {
product := p.Ctx.Command.Name
if product == "new" {
newFlag := p.GetCtxString("new")
if newFlag == "true" { // HACK: need to fix GetCtxString
return p.getNewCmdURL(), nil
}

var baseURL string
product := p.Ctx.Command.Name
switch product {
case drive:
baseURL = "https://drive.google.com"
Expand Down Expand Up @@ -135,8 +135,8 @@ func (p *Provider) join(additionPath string) {
}

func (p *Provider) getNewCmdURL() string {
parentCmd := strings.Split(p.Ctx.Command.FullName(), " ")[0]
switch parentCmd {
product := p.Ctx.Command.Name
switch product {
case document:
return "https://document.new"
case spreadsheets:
Expand Down

0 comments on commit 31c2e72

Please sign in to comment.