Skip to content

Commit 22a4d68

Browse files
committed
Initial commit
0 parents  commit 22a4d68

File tree

17 files changed

+1089
-0
lines changed

17 files changed

+1089
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trellis-cli
2+
dist
3+
tmp

.goreleaser.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
project_name: trellis
2+
before:
3+
hooks:
4+
- go mod download
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- darwin
11+
- windows
12+
goarch:
13+
- 386
14+
- amd64
15+
archive:
16+
replacements:
17+
darwin: Darwin
18+
linux: Linux
19+
windows: Windows
20+
386: i386
21+
amd64: x86_64
22+
format_overrides:
23+
- goos: windows
24+
format: zip
25+
checksum:
26+
name_template: '{{ .ProjectName }}_checksums.txt'
27+
changelog:
28+
sort: asc
29+
filters:
30+
exclude:
31+
- '^docs:'
32+
- '^test:'

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: go
2+
go:
3+
- 1.11.x
4+
5+
env:
6+
- GO111MODULE=on
7+
8+
deploy:
9+
- provider: script
10+
skip_cleanup: true
11+
script: curl -sL https://git.io/goreleaser | bash
12+
on:
13+
tags: true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Scott Walkinshaw
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# trellis-cli
2+
3+
TODO: Write a description here
4+
5+
## Installation
6+
7+
TODO: Write installation instructions here
8+
9+
## Usage
10+
11+
TODO: Write usage instructions here
12+
13+
## Development
14+
15+
TODO: Write development instructions here
16+
17+
## Contributing
18+
19+
1. Fork it ( https://github.com/swalkinshaw/trellis-cli/fork )
20+
2. Create your feature branch (git checkout -b my-new-feature)
21+
3. Commit your changes (git commit -am 'Add some feature')
22+
4. Push to the branch (git push origin my-new-feature)
23+
5. Create a new Pull Request
24+
25+
## Contributors
26+
27+
- [swalkinshaw](https://github.com/swalkinshaw) Scott Walkinshaw - creator, maintainer

cmd/deploy.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os/exec"
7+
"strings"
8+
9+
"github.com/mitchellh/cli"
10+
"github.com/posener/complete"
11+
"trellis-cli/trellis"
12+
)
13+
14+
type DeployCommand struct {
15+
UI cli.Ui
16+
Trellis *trellis.Trellis
17+
}
18+
19+
func (c *DeployCommand) Run(args []string) int {
20+
c.Trellis.EnforceValid(c.UI)
21+
22+
var environment string
23+
var siteName string
24+
25+
switch len(args) {
26+
case 0:
27+
c.UI.Output(c.Help())
28+
return 1
29+
case 1:
30+
c.UI.Error("Missing SITE argument\n")
31+
c.UI.Output(c.Help())
32+
return 1
33+
case 2:
34+
environment = args[0]
35+
siteName = args[1]
36+
default:
37+
c.UI.Error(fmt.Sprintf("Error: too many arguments (expected 2, got %d)\n", len(args)))
38+
c.UI.Output(c.Help())
39+
return 1
40+
}
41+
42+
deploy := exec.Command("./bin/deploy.sh", environment, siteName)
43+
logCmd(deploy, true)
44+
err := deploy.Run()
45+
46+
if err != nil {
47+
log.Fatal(err)
48+
}
49+
50+
return 0
51+
}
52+
53+
func (c *DeployCommand) Synopsis() string {
54+
return "Deploys a site to the specified environment."
55+
}
56+
57+
func (c *DeployCommand) Help() string {
58+
helpText := `
59+
Usage: trellis deploy [options] ENVIRONMENT SITE
60+
61+
Deploys a site to the specified environment.
62+
63+
See https://roots.io/trellis/docs/deploys/ for more information on deploys with Trellis.
64+
65+
Deploy a site to production:
66+
67+
$ trellis deploy production example.com
68+
69+
Arguments:
70+
ENVIRONMENT Name of environment (ie: production)
71+
SITE Name of the site (ie: example.com)
72+
73+
Options:
74+
-h, --help show this help
75+
`
76+
77+
return strings.TrimSpace(helpText)
78+
}
79+
80+
func (c *DeployCommand) AutocompleteArgs() complete.Predictor {
81+
return c.PredictSite()
82+
}
83+
84+
func (c *DeployCommand) AutocompleteFlags() complete.Flags {
85+
return complete.Flags{}
86+
}
87+
88+
func (c *DeployCommand) PredictSite() complete.PredictFunc {
89+
return func(args complete.Args) []string {
90+
switch len(args.Completed) {
91+
case 1:
92+
return c.Trellis.EnvironmentNames()
93+
case 2:
94+
return c.Trellis.SiteNamesFromEnvironment(args.LastCompleted)
95+
default:
96+
return []string{}
97+
}
98+
}
99+
}

cmd/exec.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"strings"
8+
)
9+
10+
func logCmd(cmd *exec.Cmd, output bool) {
11+
cmd.Stderr = os.Stderr
12+
13+
if output {
14+
cmd.Stdout = os.Stdout
15+
}
16+
17+
fmt.Println("Running command =>", strings.Join(cmd.Args, " "))
18+
}

cmd/galaxy.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cmd
2+
3+
import (
4+
"strings"
5+
6+
"github.com/mitchellh/cli"
7+
"trellis-cli/trellis"
8+
)
9+
10+
type GalaxyCommand struct {
11+
UI cli.Ui
12+
Trellis *trellis.Trellis
13+
}
14+
15+
func (c *GalaxyCommand) Run(args []string) int {
16+
c.Trellis.EnforceValid(c.UI)
17+
c.UI.Output(c.Help())
18+
19+
return 0
20+
}
21+
22+
func (c *GalaxyCommand) Synopsis() string {
23+
return "Commands for Ansible Galaxy"
24+
}
25+
26+
func (c *GalaxyCommand) Help() string {
27+
helpText := `
28+
Usage: trellis galaxy <subcommand> [<args>]
29+
`
30+
31+
return strings.TrimSpace(helpText)
32+
}

cmd/galaxy_install.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cmd
2+
3+
import (
4+
"github.com/mitchellh/cli"
5+
"log"
6+
"os/exec"
7+
"strings"
8+
"trellis-cli/trellis"
9+
)
10+
11+
type GalaxyInstallCommand struct {
12+
UI cli.Ui
13+
Trellis *trellis.Trellis
14+
}
15+
16+
func (c *GalaxyInstallCommand) Run(args []string) int {
17+
c.Trellis.EnforceValid(c.UI)
18+
19+
galaxyInstall := exec.Command("ansible-galaxy", "install", "-r", "requirements.yml")
20+
logCmd(galaxyInstall, true)
21+
err := galaxyInstall.Run()
22+
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
27+
return 0
28+
}
29+
30+
func (c *GalaxyInstallCommand) Synopsis() string {
31+
return "Installs Ansible Galaxy roles"
32+
}
33+
34+
func (c *GalaxyInstallCommand) Help() string {
35+
helpText := `
36+
Usage: trellis galaxy install
37+
38+
Installs Ansible Galaxy roles.
39+
40+
See https://roots.io/trellis/docs/remote-server-setup/#requirements for more information.
41+
42+
Options:
43+
-h, --help show this help
44+
`
45+
46+
return strings.TrimSpace(helpText)
47+
}

cmd/info.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/mitchellh/cli"
8+
"trellis-cli/trellis"
9+
)
10+
11+
type InfoCommand struct {
12+
UI cli.Ui
13+
Trellis *trellis.Trellis
14+
}
15+
16+
func (c *InfoCommand) Run(args []string) int {
17+
c.Trellis.EnforceValid(c.UI)
18+
19+
var siteNames []string
20+
21+
for name, sites := range c.Trellis.Environments {
22+
for _, site := range sites {
23+
siteNames = append(siteNames, site.Name)
24+
}
25+
26+
c.UI.Info(fmt.Sprintf("%s => %s", name, strings.Join(siteNames, ", ")))
27+
}
28+
return 0
29+
}
30+
31+
func (c *InfoCommand) Synopsis() string {
32+
return "Displays information about this Trellis project"
33+
}
34+
35+
func (c *InfoCommand) Help() string {
36+
helpText := `
37+
Usage: trellis info [options]
38+
39+
Displays information about this Trellis project
40+
41+
Options:
42+
-h, --help show this help
43+
`
44+
45+
return strings.TrimSpace(helpText)
46+
}

0 commit comments

Comments
 (0)