-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a567be
Showing
7 changed files
with
545 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
trellis-cli-kinsta | ||
dist | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd | ||
|
||
import "fmt" | ||
|
||
type CommandArgumentValidator struct { | ||
required int | ||
optional int | ||
} | ||
|
||
func (c *CommandArgumentValidator) validate(args []string) (err error) { | ||
argCount := len(args) | ||
totalArgs := c.required + c.optional | ||
|
||
expectedCount := fmt.Sprintf("exactly %d", c.required) | ||
if c.optional > 0 { | ||
expectedCount = fmt.Sprintf("between %d and %d", c.required, totalArgs) | ||
} | ||
|
||
if argCount > totalArgs { | ||
return fmt.Errorf("Error: too many arguments (expected %s, got %d)\n", expectedCount, argCount) | ||
} | ||
if argCount < c.required { | ||
return fmt.Errorf("Error: missing arguments (expected %s, got %d)\n", expectedCount, argCount) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"strings" | ||
|
||
"github.com/ItinerisLtd/trellis-cli-kinsta/kinsta" | ||
"github.com/mitchellh/cli" | ||
"github.com/roots/trellis-cli/trellis" | ||
) | ||
|
||
func NewSiteListCommand(ui cli.Ui, trellis *trellis.Trellis) *SiteListCommand { | ||
c := &SiteListCommand{UI: ui, Trellis: trellis} | ||
c.init() | ||
return c | ||
} | ||
|
||
type SiteListCommand struct { | ||
UI cli.Ui | ||
Trellis *trellis.Trellis | ||
flags *flag.FlagSet | ||
company string | ||
} | ||
|
||
func (c *SiteListCommand) init() { | ||
c.flags = flag.NewFlagSet("", flag.ContinueOnError) | ||
c.flags.Usage = func() { c.UI.Info(c.Help()) } | ||
c.flags.StringVar(&c.company, "company", "", "The company ID to query.") | ||
} | ||
|
||
func (c *SiteListCommand) Run(args []string) int { | ||
if err := c.Trellis.LoadProject(); err != nil { | ||
c.UI.Error(err.Error()) | ||
return 1 | ||
} | ||
|
||
c.Trellis.CheckVirtualenv(c.UI) | ||
|
||
if err := c.flags.Parse(args); err != nil { | ||
return 1 | ||
} | ||
|
||
args = c.flags.Args() | ||
|
||
accessToken, err := kinsta.GetAccessToken(c.UI) | ||
if err != nil { | ||
c.UI.Error("Error: DigitalOcean access token is required.") | ||
return 1 | ||
} | ||
kinsta.ListSites(c.UI, accessToken, c.company) | ||
|
||
return 0 | ||
} | ||
|
||
func (c *SiteListCommand) Synopsis() string { | ||
return "help me" | ||
} | ||
|
||
func (c *SiteListCommand) Help() string { | ||
helpText := ` | ||
Usage: trellis kinsta site list [options] | ||
List all sites associated to the given company ID: | ||
$ trellis kinsta site list --company=123 | ||
Arguments: | ||
ENVIRONMENT Name of environment (ie: production) | ||
Options: | ||
--company The company ID to query | ||
-h, --help show this help | ||
` | ||
|
||
return strings.TrimSpace(helpText) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module github.com/ItinerisLtd/trellis-cli-kinsta | ||
|
||
go 1.21.6 | ||
|
||
require ( | ||
github.com/fatih/color v1.15.0 | ||
github.com/mitchellh/cli v1.1.5 | ||
github.com/roots/trellis-cli v1.11.1 | ||
) | ||
|
||
require ( | ||
github.com/Masterminds/goutils v1.1.1 // indirect | ||
github.com/Masterminds/semver/v3 v3.1.1 // indirect | ||
github.com/Masterminds/sprig/v3 v3.2.2 // indirect | ||
github.com/armon/go-radix v1.0.0 // indirect | ||
github.com/bgentry/speakeasy v0.1.0 // indirect | ||
github.com/chzyer/readline v1.5.0 // indirect | ||
github.com/digitalocean/godo v1.83.0 // indirect | ||
github.com/dsnet/compress v0.0.1 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/go-querystring v1.1.0 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||
github.com/huandu/xstrings v1.3.2 // indirect | ||
github.com/imdario/mergo v0.3.13 // indirect | ||
github.com/manifoldco/promptui v0.9.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/mattn/go-runewidth v0.0.13 // indirect | ||
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 // indirect | ||
github.com/mholt/archiver v3.1.1+incompatible // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/nwaples/rardecode v1.1.3 // indirect | ||
github.com/pierrec/lz4 v2.6.1+incompatible // indirect | ||
github.com/posener/complete v1.2.3 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/shopspring/decimal v1.3.1 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/theckman/yacspin v0.13.12 // indirect | ||
github.com/ulikunitz/xz v0.5.10 // indirect | ||
github.com/weppos/publicsuffix-go v0.30.1 // indirect | ||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect | ||
golang.org/x/crypto v0.11.0 // indirect | ||
golang.org/x/net v0.12.0 // indirect | ||
golang.org/x/oauth2 v0.10.0 // indirect | ||
golang.org/x/sys v0.10.0 // indirect | ||
golang.org/x/text v0.11.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/alessio/shellescape.v1 v1.0.0-20170105083845-52074bc9df61 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
Oops, something went wrong.