Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
swalkinshaw committed Jan 17, 2019
0 parents commit 22a4d68
Show file tree
Hide file tree
Showing 17 changed files with 1,089 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trellis-cli
dist
tmp
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
project_name: trellis
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
archive:
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go
go:
- 1.11.x

env:
- GO111MODULE=on

deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Scott Walkinshaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# trellis-cli

TODO: Write a description here

## Installation

TODO: Write installation instructions here

## Usage

TODO: Write usage instructions here

## Development

TODO: Write development instructions here

## Contributing

1. Fork it ( https://github.com/swalkinshaw/trellis-cli/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

## Contributors

- [swalkinshaw](https://github.com/swalkinshaw) Scott Walkinshaw - creator, maintainer
99 changes: 99 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package cmd

import (
"fmt"
"log"
"os/exec"
"strings"

"github.com/mitchellh/cli"
"github.com/posener/complete"
"trellis-cli/trellis"
)

type DeployCommand struct {
UI cli.Ui
Trellis *trellis.Trellis
}

func (c *DeployCommand) Run(args []string) int {
c.Trellis.EnforceValid(c.UI)

var environment string
var siteName string

switch len(args) {
case 0:
c.UI.Output(c.Help())
return 1
case 1:
c.UI.Error("Missing SITE argument\n")
c.UI.Output(c.Help())
return 1
case 2:
environment = args[0]
siteName = args[1]
default:
c.UI.Error(fmt.Sprintf("Error: too many arguments (expected 2, got %d)\n", len(args)))
c.UI.Output(c.Help())
return 1
}

deploy := exec.Command("./bin/deploy.sh", environment, siteName)
logCmd(deploy, true)
err := deploy.Run()

if err != nil {
log.Fatal(err)
}

return 0
}

func (c *DeployCommand) Synopsis() string {
return "Deploys a site to the specified environment."
}

func (c *DeployCommand) Help() string {
helpText := `
Usage: trellis deploy [options] ENVIRONMENT SITE
Deploys a site to the specified environment.
See https://roots.io/trellis/docs/deploys/ for more information on deploys with Trellis.
Deploy a site to production:
$ trellis deploy production example.com
Arguments:
ENVIRONMENT Name of environment (ie: production)
SITE Name of the site (ie: example.com)
Options:
-h, --help show this help
`

return strings.TrimSpace(helpText)
}

func (c *DeployCommand) AutocompleteArgs() complete.Predictor {
return c.PredictSite()
}

func (c *DeployCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{}
}

func (c *DeployCommand) PredictSite() complete.PredictFunc {
return func(args complete.Args) []string {
switch len(args.Completed) {
case 1:
return c.Trellis.EnvironmentNames()
case 2:
return c.Trellis.SiteNamesFromEnvironment(args.LastCompleted)
default:
return []string{}
}
}
}
18 changes: 18 additions & 0 deletions cmd/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"fmt"
"os"
"os/exec"
"strings"
)

func logCmd(cmd *exec.Cmd, output bool) {
cmd.Stderr = os.Stderr

if output {
cmd.Stdout = os.Stdout
}

fmt.Println("Running command =>", strings.Join(cmd.Args, " "))
}
32 changes: 32 additions & 0 deletions cmd/galaxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"strings"

"github.com/mitchellh/cli"
"trellis-cli/trellis"
)

type GalaxyCommand struct {
UI cli.Ui
Trellis *trellis.Trellis
}

func (c *GalaxyCommand) Run(args []string) int {
c.Trellis.EnforceValid(c.UI)
c.UI.Output(c.Help())

return 0
}

func (c *GalaxyCommand) Synopsis() string {
return "Commands for Ansible Galaxy"
}

func (c *GalaxyCommand) Help() string {
helpText := `
Usage: trellis galaxy <subcommand> [<args>]
`

return strings.TrimSpace(helpText)
}
47 changes: 47 additions & 0 deletions cmd/galaxy_install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"github.com/mitchellh/cli"
"log"
"os/exec"
"strings"
"trellis-cli/trellis"
)

type GalaxyInstallCommand struct {
UI cli.Ui
Trellis *trellis.Trellis
}

func (c *GalaxyInstallCommand) Run(args []string) int {
c.Trellis.EnforceValid(c.UI)

galaxyInstall := exec.Command("ansible-galaxy", "install", "-r", "requirements.yml")
logCmd(galaxyInstall, true)
err := galaxyInstall.Run()

if err != nil {
log.Fatal(err)
}

return 0
}

func (c *GalaxyInstallCommand) Synopsis() string {
return "Installs Ansible Galaxy roles"
}

func (c *GalaxyInstallCommand) Help() string {
helpText := `
Usage: trellis galaxy install
Installs Ansible Galaxy roles.
See https://roots.io/trellis/docs/remote-server-setup/#requirements for more information.
Options:
-h, --help show this help
`

return strings.TrimSpace(helpText)
}
46 changes: 46 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"
"strings"

"github.com/mitchellh/cli"
"trellis-cli/trellis"
)

type InfoCommand struct {
UI cli.Ui
Trellis *trellis.Trellis
}

func (c *InfoCommand) Run(args []string) int {
c.Trellis.EnforceValid(c.UI)

var siteNames []string

for name, sites := range c.Trellis.Environments {
for _, site := range sites {
siteNames = append(siteNames, site.Name)
}

c.UI.Info(fmt.Sprintf("%s => %s", name, strings.Join(siteNames, ", ")))
}
return 0
}

func (c *InfoCommand) Synopsis() string {
return "Displays information about this Trellis project"
}

func (c *InfoCommand) Help() string {
helpText := `
Usage: trellis info [options]
Displays information about this Trellis project
Options:
-h, --help show this help
`

return strings.TrimSpace(helpText)
}
Loading

0 comments on commit 22a4d68

Please sign in to comment.