diff --git a/drone/agent/agent.go b/drone/agent/agent.go index 33493b6eb..e7683ee50 100644 --- a/drone/agent/agent.go +++ b/drone/agent/agent.go @@ -24,8 +24,8 @@ import ( "github.com/urfave/cli" ) -// AgentCmd is the exported command for starting the drone agent. -var AgentCmd = cli.Command{ +// Command exports the agent command. +var Command = cli.Command{ Name: "agent", Usage: "starts the drone agent", Action: loop, diff --git a/drone/build.go b/drone/build/build.go similarity index 75% rename from drone/build.go rename to drone/build/build.go index 78572952f..e4d6a8233 100644 --- a/drone/build.go +++ b/drone/build/build.go @@ -1,8 +1,9 @@ -package main +package build import "github.com/urfave/cli" -var buildCmd = cli.Command{ +// Command exports the build command set. +var Command = cli.Command{ Name: "build", Usage: "manage builds", Subcommands: []cli.Command{ diff --git a/drone/build_approve.go b/drone/build/build_approve.go similarity index 79% rename from drone/build_approve.go rename to drone/build/build_approve.go index a9dfff482..3575c075d 100644 --- a/drone/build_approve.go +++ b/drone/build/build_approve.go @@ -1,9 +1,10 @@ -package main +package build import ( "fmt" "strconv" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -15,7 +16,7 @@ var buildApproveCmd = cli.Command{ func buildApprove(c *cli.Context) (err error) { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } @@ -24,7 +25,7 @@ func buildApprove(c *cli.Context) (err error) { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_decline.go b/drone/build/build_decline.go similarity index 79% rename from drone/build_decline.go rename to drone/build/build_decline.go index fb4ce35d3..bc6a6aa19 100644 --- a/drone/build_decline.go +++ b/drone/build/build_decline.go @@ -1,9 +1,10 @@ -package main +package build import ( "fmt" "strconv" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -15,7 +16,7 @@ var buildDeclineCmd = cli.Command{ func buildDecline(c *cli.Context) (err error) { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } @@ -24,7 +25,7 @@ func buildDecline(c *cli.Context) (err error) { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_info.go b/drone/build/build_info.go similarity index 89% rename from drone/build_info.go rename to drone/build/build_info.go index 17df7882e..1235fc437 100644 --- a/drone/build_info.go +++ b/drone/build/build_info.go @@ -1,10 +1,11 @@ -package main +package build import ( "os" "strconv" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -23,13 +24,13 @@ var buildInfoCmd = cli.Command{ func buildInfo(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } buildArg := c.Args().Get(1) - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_last.go b/drone/build/build_last.go similarity index 84% rename from drone/build_last.go rename to drone/build/build_last.go index b1eb294ad..58d354b26 100644 --- a/drone/build_last.go +++ b/drone/build/build_last.go @@ -1,9 +1,10 @@ -package main +package build import ( "os" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -27,12 +28,12 @@ var buildLastCmd = cli.Command{ func buildLast(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_list.go b/drone/build/build_list.go similarity index 92% rename from drone/build_list.go rename to drone/build/build_list.go index 9d8002b57..27dfed0ee 100644 --- a/drone/build_list.go +++ b/drone/build/build_list.go @@ -1,9 +1,10 @@ -package main +package build import ( "os" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -39,12 +40,12 @@ var buildListCmd = cli.Command{ func buildList(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_logs.go b/drone/build/build_logs.go similarity index 91% rename from drone/build_logs.go rename to drone/build/build_logs.go index 2e6f8850a..8a78edc0f 100644 --- a/drone/build_logs.go +++ b/drone/build/build_logs.go @@ -1,4 +1,4 @@ -package main +package build import ( "encoding/json" @@ -6,6 +6,7 @@ import ( "strconv" "github.com/cncd/pipeline/pipeline/rpc" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -21,12 +22,12 @@ func buildLogsDisabled(c *cli.Context) error { func buildLogs(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_queue.go b/drone/build/build_queue.go similarity index 91% rename from drone/build_queue.go rename to drone/build/build_queue.go index 85c8596ec..f5110e591 100644 --- a/drone/build_queue.go +++ b/drone/build/build_queue.go @@ -1,10 +1,11 @@ -package main +package build import ( "fmt" "os" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -23,7 +24,7 @@ var buildQueueCmd = cli.Command{ func buildQueue(c *cli.Context) error { - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/build_start.go b/drone/build/build_start.go similarity index 85% rename from drone/build_start.go rename to drone/build/build_start.go index d965866a5..97625495a 100644 --- a/drone/build_start.go +++ b/drone/build/build_start.go @@ -1,9 +1,10 @@ -package main +package build import ( "fmt" "strconv" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" "github.com/urfave/cli" ) @@ -26,12 +27,12 @@ var buildStartCmd = cli.Command{ func buildStart(c *cli.Context) (err error) { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -52,7 +53,7 @@ func buildStart(c *cli.Context) (err error) { } } - params := parseKVPairs(c.StringSlice("param")) + params := internal.ParseKeyPair(c.StringSlice("param")) var build *model.Build if c.Bool("fork") { diff --git a/drone/build_stop.go b/drone/build/build_stop.go similarity index 81% rename from drone/build_stop.go rename to drone/build/build_stop.go index 0edfed0aa..23ec1ee0b 100644 --- a/drone/build_stop.go +++ b/drone/build/build_stop.go @@ -1,9 +1,10 @@ -package main +package build import ( "fmt" "strconv" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -15,7 +16,7 @@ var buildStopCmd = cli.Command{ func buildStop(c *cli.Context) (err error) { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } @@ -28,7 +29,7 @@ func buildStop(c *cli.Context) (err error) { job = 1 } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/deploy.go b/drone/deploy/deploy.go similarity index 85% rename from drone/deploy.go rename to drone/deploy/deploy.go index e804122ec..e14f5423f 100644 --- a/drone/deploy.go +++ b/drone/deploy/deploy.go @@ -1,4 +1,4 @@ -package main +package deploy import ( "fmt" @@ -6,11 +6,14 @@ import ( "os" "strconv" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" + "github.com/urfave/cli" ) -var deployCmd = cli.Command{ +// Command exports the deploy command. +var Command = cli.Command{ Name: "deploy", Usage: "deploy code", Action: deploy, @@ -44,12 +47,12 @@ var deployCmd = cli.Command{ func deploy(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -62,9 +65,9 @@ func deploy(c *cli.Context) error { var number int if buildArg == "last" { // Fetch the build number from the last build - builds, err := client.BuildList(owner, name) - if err != nil { - return err + builds, berr := client.BuildList(owner, name) + if berr != nil { + return berr } for _, build := range builds { if branch != "" && build.Branch != branch { @@ -95,7 +98,7 @@ func deploy(c *cli.Context) error { return fmt.Errorf("Please specify the target environment (ie production)") } - params := parseKVPairs(c.StringSlice("param")) + params := internal.ParseKeyPair(c.StringSlice("param")) deploy, err := client.Deploy(owner, name, number, env, params) if err != nil { diff --git a/drone/exec.go b/drone/exec/exec.go similarity index 99% rename from drone/exec.go rename to drone/exec/exec.go index 414013544..fc4f8495d 100644 --- a/drone/exec.go +++ b/drone/exec/exec.go @@ -1,4 +1,4 @@ -package main +package exec import ( "context" @@ -23,7 +23,8 @@ import ( "github.com/urfave/cli" ) -var execCmd = cli.Command{ +// Command exports the exec command. +var Command = cli.Command{ Name: "exec", Usage: "execute a local build", Action: func(c *cli.Context) { diff --git a/drone/info.go b/drone/info/info.go similarity index 69% rename from drone/info.go rename to drone/info/info.go index d5d288844..49877c7b9 100644 --- a/drone/info.go +++ b/drone/info/info.go @@ -1,27 +1,31 @@ -package main +package info import ( "os" "text/template" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) -var infoCmd = cli.Command{ +// Command exports the info command. +var Command = cli.Command{ Name: "info", Usage: "show information about the current user", Action: info, Flags: []cli.Flag{ cli.StringFlag{ - Name: "format", - Usage: "format output", - Value: tmplUserInfo, + Name: "format", + Usage: "format output", + Value: tmplInfo, + Hidden: true, }, }, } func info(c *cli.Context) error { - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/util.go b/drone/internal/util.go similarity index 80% rename from drone/util.go rename to drone/internal/util.go index aa515f8f6..5104680de 100644 --- a/drone/util.go +++ b/drone/internal/util.go @@ -1,4 +1,4 @@ -package main +package internal import ( "crypto/tls" @@ -13,7 +13,8 @@ import ( "github.com/urfave/cli" ) -func newClient(c *cli.Context) (client.Client, error) { +// NewClient returns a new client from the CLI context. +func NewClient(c *cli.Context) (client.Client, error) { var token = c.GlobalString("token") var server = strings.TrimRight(c.GlobalString("server"), "/") @@ -34,7 +35,8 @@ func newClient(c *cli.Context) (client.Client, error) { return client.NewClientTokenTLS(server, token, tlsConfig) } -func parseRepo(str string) (user, repo string, err error) { +// ParseRepo parses the repository owner and name from a string. +func ParseRepo(str string) (user, repo string, err error) { var parts = strings.Split(str, "/") if len(parts) != 2 { err = fmt.Errorf("Error: Invalid or missing repository. eg octocat/hello-world.") @@ -62,7 +64,8 @@ func stringInSlice(a string, list []string) bool { return false } -func parseKVPairs(p []string) map[string]string { +// ParseKeyPair parses a key=value pair. +func ParseKeyPair(p []string) map[string]string { params := map[string]string{} for _, i := range p { parts := strings.Split(i, "=") diff --git a/drone/util_test.go b/drone/internal/util_test.go similarity index 82% rename from drone/util_test.go rename to drone/internal/util_test.go index b7856f28b..41baa6db4 100644 --- a/drone/util_test.go +++ b/drone/internal/util_test.go @@ -1,10 +1,10 @@ -package main +package internal import "testing" -func Test_parseKVPairs(t *testing.T) { +func TestParseKeyPair(t *testing.T) { s := []string{"FOO=bar", "BAR=", "INVALID"} - p := parseKVPairs(s) + p := ParseKeyPair(s) if p["FOO"] != "bar" { t.Errorf("Wanted %q, got %q.", "bar", p["FOO"]) } diff --git a/drone/main.go b/drone/main.go index a39074ce9..5d027692b 100644 --- a/drone/main.go +++ b/drone/main.go @@ -5,6 +5,15 @@ import ( "os" "github.com/drone/drone/drone/agent" + "github.com/drone/drone/drone/build" + "github.com/drone/drone/drone/deploy" + "github.com/drone/drone/drone/exec" + "github.com/drone/drone/drone/info" + "github.com/drone/drone/drone/registry" + "github.com/drone/drone/drone/repo" + "github.com/drone/drone/drone/secret" + "github.com/drone/drone/drone/server" + "github.com/drone/drone/drone/user" "github.com/drone/drone/version" "github.com/ianschenck/envflag" @@ -32,16 +41,16 @@ func main() { }, } app.Commands = []cli.Command{ - agent.AgentCmd, - buildCmd, - deployCmd, - execCmd, - infoCmd, - registryCmd, - secretCmd, - serverCmd, - repoCmd, - userCmd, + agent.Command, + build.Command, + deploy.Command, + exec.Command, + info.Command, + registry.Command, + secret.Command, + server.Command, + repo.Command, + user.Command, } if err := app.Run(os.Args); err != nil { diff --git a/drone/registry.go b/drone/registry/registry.go similarity index 71% rename from drone/registry.go rename to drone/registry/registry.go index da479796a..60855a3ba 100644 --- a/drone/registry.go +++ b/drone/registry/registry.go @@ -1,8 +1,9 @@ -package main +package registry import "github.com/urfave/cli" -var registryCmd = cli.Command{ +// Command exports the registry command set. +var Command = cli.Command{ Name: "registry", Usage: "manage registries", Subcommands: []cli.Command{ diff --git a/drone/registry_add.go b/drone/registry/registry_add.go similarity index 85% rename from drone/registry_add.go rename to drone/registry/registry_add.go index a50e3a152..0d6dc1f59 100644 --- a/drone/registry_add.go +++ b/drone/registry/registry_add.go @@ -1,10 +1,12 @@ -package main +package registry import ( "io/ioutil" "strings" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" + "github.com/urfave/cli" ) @@ -43,11 +45,11 @@ func registryCreate(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -58,9 +60,9 @@ func registryCreate(c *cli.Context) error { } if strings.HasPrefix(registry.Password, "@") { path := strings.TrimPrefix(registry.Password, "@") - out, err := ioutil.ReadFile(path) - if err != nil { - return err + out, ferr := ioutil.ReadFile(path) + if ferr != nil { + return ferr } registry.Password = string(out) } diff --git a/drone/registry_info.go b/drone/registry/registry_info.go similarity index 87% rename from drone/registry_info.go rename to drone/registry/registry_info.go index 09880c95e..8d4417f7b 100644 --- a/drone/registry_info.go +++ b/drone/registry/registry_info.go @@ -1,9 +1,11 @@ -package main +package registry import ( "html/template" "os" + "github.com/drone/drone/drone/internal" + "github.com/urfave/cli" ) @@ -39,11 +41,11 @@ func registryInfo(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/registry_list.go b/drone/registry/registry_list.go similarity index 87% rename from drone/registry_list.go rename to drone/registry/registry_list.go index 1a5b468ae..ae7eb189f 100644 --- a/drone/registry_list.go +++ b/drone/registry/registry_list.go @@ -1,10 +1,12 @@ -package main +package registry import ( "html/template" "os" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var registryListCmd = cli.Command{ @@ -33,11 +35,11 @@ func registryList(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/registry_rm.go b/drone/registry/registry_rm.go similarity index 77% rename from drone/registry_rm.go rename to drone/registry/registry_rm.go index ff18eda2e..82acd90c7 100644 --- a/drone/registry_rm.go +++ b/drone/registry/registry_rm.go @@ -1,6 +1,10 @@ -package main +package registry -import "github.com/urfave/cli" +import ( + "github.com/drone/drone/drone/internal" + + "github.com/urfave/cli" +) var registryDeleteCmd = cli.Command{ Name: "rm", @@ -27,11 +31,11 @@ func registryDelete(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/registry_set.go b/drone/registry/registry_set.go similarity index 85% rename from drone/registry_set.go rename to drone/registry/registry_set.go index 7bf6eddc3..c64f7ab42 100644 --- a/drone/registry_set.go +++ b/drone/registry/registry_set.go @@ -1,10 +1,12 @@ -package main +package registry import ( "io/ioutil" "strings" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" + "github.com/urfave/cli" ) @@ -43,11 +45,11 @@ func registryUpdate(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -58,9 +60,9 @@ func registryUpdate(c *cli.Context) error { } if strings.HasPrefix(registry.Password, "@") { path := strings.TrimPrefix(registry.Password, "@") - out, err := ioutil.ReadFile(path) - if err != nil { - return err + out, ferr := ioutil.ReadFile(path) + if ferr != nil { + return ferr } registry.Password = string(out) } diff --git a/drone/repo.go b/drone/repo/repo.go similarity index 73% rename from drone/repo.go rename to drone/repo/repo.go index a8154864f..72b1cdc02 100644 --- a/drone/repo.go +++ b/drone/repo/repo.go @@ -1,8 +1,9 @@ -package main +package repo import "github.com/urfave/cli" -var repoCmd = cli.Command{ +// Command exports the repository command. +var Command = cli.Command{ Name: "repo", Usage: "manage repositories", Subcommands: []cli.Command{ diff --git a/drone/repo_add.go b/drone/repo/repo_add.go similarity index 75% rename from drone/repo_add.go rename to drone/repo/repo_add.go index 41965dc84..2bda1a104 100644 --- a/drone/repo_add.go +++ b/drone/repo/repo_add.go @@ -1,8 +1,9 @@ -package main +package repo import ( "fmt" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -14,12 +15,12 @@ var repoAddCmd = cli.Command{ func repoAdd(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_chown.go b/drone/repo/repo_chown.go similarity index 77% rename from drone/repo_chown.go rename to drone/repo/repo_chown.go index f74fdafb7..effa95682 100644 --- a/drone/repo_chown.go +++ b/drone/repo/repo_chown.go @@ -1,8 +1,9 @@ -package main +package repo import ( "fmt" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -14,12 +15,12 @@ var repoChownCmd = cli.Command{ func repoChown(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_info.go b/drone/repo/repo_info.go similarity index 86% rename from drone/repo_info.go rename to drone/repo/repo_info.go index 9cb9bc922..cacf342bf 100644 --- a/drone/repo_info.go +++ b/drone/repo/repo_info.go @@ -1,9 +1,10 @@ -package main +package repo import ( "os" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -22,12 +23,12 @@ var repoInfoCmd = cli.Command{ func repoInfo(c *cli.Context) error { arg := c.Args().First() - owner, name, err := parseRepo(arg) + owner, name, err := internal.ParseRepo(arg) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_list.go b/drone/repo/repo_list.go similarity index 90% rename from drone/repo_list.go rename to drone/repo/repo_list.go index 5709d255a..00099b79d 100644 --- a/drone/repo_list.go +++ b/drone/repo/repo_list.go @@ -1,9 +1,10 @@ -package main +package repo import ( "os" "text/template" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -25,7 +26,7 @@ var repoListCmd = cli.Command{ } func repoList(c *cli.Context) error { - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_repair.go b/drone/repo/repo_repair.go similarity index 70% rename from drone/repo_repair.go rename to drone/repo/repo_repair.go index 1169ce496..f5507c314 100644 --- a/drone/repo_repair.go +++ b/drone/repo/repo_repair.go @@ -1,6 +1,7 @@ -package main +package repo import ( + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -12,11 +13,11 @@ var repoRepairCmd = cli.Command{ func repoRepair(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_rm.go b/drone/repo/repo_rm.go similarity index 75% rename from drone/repo_rm.go rename to drone/repo/repo_rm.go index c2c5cbd28..d71c2c4bd 100644 --- a/drone/repo_rm.go +++ b/drone/repo/repo_rm.go @@ -1,8 +1,9 @@ -package main +package repo import ( "fmt" + "github.com/drone/drone/drone/internal" "github.com/urfave/cli" ) @@ -14,12 +15,12 @@ var repoRemoveCmd = cli.Command{ func repoRemove(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/repo_update.go b/drone/repo/repo_update.go similarity index 90% rename from drone/repo_update.go rename to drone/repo/repo_update.go index 40c209c8f..9f9844888 100644 --- a/drone/repo_update.go +++ b/drone/repo/repo_update.go @@ -1,9 +1,10 @@ -package main +package repo import ( "fmt" "time" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" "github.com/urfave/cli" ) @@ -34,12 +35,12 @@ var repoUpdateCmd = cli.Command{ func repoUpdate(c *cli.Context) error { repo := c.Args().First() - owner, name, err := parseRepo(repo) + owner, name, err := internal.ParseRepo(repo) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/secret.go b/drone/secret/secret.go similarity index 71% rename from drone/secret.go rename to drone/secret/secret.go index 648eade57..fc1ee2353 100644 --- a/drone/secret.go +++ b/drone/secret/secret.go @@ -1,8 +1,9 @@ -package main +package secret import "github.com/urfave/cli" -var secretCmd = cli.Command{ +// Command exports the secret command. +var Command = cli.Command{ Name: "secret", Usage: "manage secrets", Subcommands: []cli.Command{ diff --git a/drone/secret_add.go b/drone/secret/secret_add.go similarity index 86% rename from drone/secret_add.go rename to drone/secret/secret_add.go index cab49ffe2..53c806846 100644 --- a/drone/secret_add.go +++ b/drone/secret/secret_add.go @@ -1,10 +1,12 @@ -package main +package secret import ( "io/ioutil" "strings" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" + "github.com/urfave/cli" ) @@ -41,11 +43,11 @@ func secretCreate(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -60,9 +62,9 @@ func secretCreate(c *cli.Context) error { } if strings.HasPrefix(secret.Value, "@") { path := strings.TrimPrefix(secret.Value, "@") - out, err := ioutil.ReadFile(path) - if err != nil { - return err + out, ferr := ioutil.ReadFile(path) + if ferr != nil { + return ferr } secret.Value = string(out) } diff --git a/drone/secret_info.go b/drone/secret/secret_info.go similarity index 87% rename from drone/secret_info.go rename to drone/secret/secret_info.go index 74f460d48..ea7faa0a1 100644 --- a/drone/secret_info.go +++ b/drone/secret/secret_info.go @@ -1,10 +1,12 @@ -package main +package secret import ( "html/template" "os" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var secretInfoCmd = cli.Command{ @@ -38,11 +40,11 @@ func secretInfo(c *cli.Context) error { if repoName == "" { repoName = c.Args().First() } - owner, name, err := parseRepo(repoName) + owner, name, err := internal.ParseRepo(repoName) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/secret_list.go b/drone/secret/secret_list.go similarity index 89% rename from drone/secret_list.go rename to drone/secret/secret_list.go index aafc06ccb..696eb361d 100644 --- a/drone/secret_list.go +++ b/drone/secret/secret_list.go @@ -1,4 +1,4 @@ -package main +package secret import ( "html/template" @@ -6,6 +6,8 @@ import ( "strings" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var secretListCmd = cli.Command{ @@ -34,11 +36,11 @@ func secretList(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/secret_rm.go b/drone/secret/secret_rm.go similarity index 76% rename from drone/secret_rm.go rename to drone/secret/secret_rm.go index 9b84d6496..6aae0f316 100644 --- a/drone/secret_rm.go +++ b/drone/secret/secret_rm.go @@ -1,6 +1,10 @@ -package main +package secret -import "github.com/urfave/cli" +import ( + "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" +) var secretDeleteCmd = cli.Command{ Name: "rm", @@ -26,11 +30,11 @@ func secretDelete(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/secret_set.go b/drone/secret/secret_set.go similarity index 84% rename from drone/secret_set.go rename to drone/secret/secret_set.go index 18f781726..e7cb9dab7 100644 --- a/drone/secret_set.go +++ b/drone/secret/secret_set.go @@ -1,10 +1,12 @@ -package main +package secret import ( "io/ioutil" "strings" + "github.com/drone/drone/drone/internal" "github.com/drone/drone/model" + "github.com/urfave/cli" ) @@ -41,11 +43,11 @@ func secretUpdate(c *cli.Context) error { if reponame == "" { reponame = c.Args().First() } - owner, name, err := parseRepo(reponame) + owner, name, err := internal.ParseRepo(reponame) if err != nil { return err } - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } @@ -57,9 +59,9 @@ func secretUpdate(c *cli.Context) error { } if strings.HasPrefix(secret.Value, "@") { path := strings.TrimPrefix(secret.Value, "@") - out, err := ioutil.ReadFile(path) - if err != nil { - return err + out, ferr := ioutil.ReadFile(path) + if ferr != nil { + return ferr } secret.Value = string(out) } diff --git a/drone/server.go b/drone/server/server.go similarity index 99% rename from drone/server.go rename to drone/server/server.go index 06d1a1b66..d01f74689 100644 --- a/drone/server.go +++ b/drone/server/server.go @@ -1,4 +1,4 @@ -package main +package server import ( "net/http" @@ -12,7 +12,8 @@ import ( "github.com/urfave/cli" ) -var serverCmd = cli.Command{ +// Command exports the server command. +var Command = cli.Command{ Name: "server", Usage: "starts the drone server daemon", Action: server, diff --git a/drone/user.go b/drone/user/user.go similarity index 67% rename from drone/user.go rename to drone/user/user.go index db0444708..03a4672a1 100644 --- a/drone/user.go +++ b/drone/user/user.go @@ -1,8 +1,9 @@ -package main +package user import "github.com/urfave/cli" -var userCmd = cli.Command{ +// Command exports the user command set. +var Command = cli.Command{ Name: "user", Usage: "manage users", Subcommands: []cli.Command{ diff --git a/drone/user_add.go b/drone/user/user_add.go similarity index 82% rename from drone/user_add.go rename to drone/user/user_add.go index 1bbe63e23..8fec74258 100644 --- a/drone/user_add.go +++ b/drone/user/user_add.go @@ -1,10 +1,12 @@ -package main +package user import ( "fmt" "github.com/drone/drone/model" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var userAddCmd = cli.Command{ @@ -16,7 +18,7 @@ var userAddCmd = cli.Command{ func userAdd(c *cli.Context) error { login := c.Args().First() - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/user_info.go b/drone/user/user_info.go similarity index 89% rename from drone/user_info.go rename to drone/user/user_info.go index 3927620b5..881a2c2e6 100644 --- a/drone/user_info.go +++ b/drone/user/user_info.go @@ -1,4 +1,4 @@ -package main +package user import ( "fmt" @@ -6,6 +6,8 @@ import ( "text/template" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var userInfoCmd = cli.Command{ @@ -22,7 +24,7 @@ var userInfoCmd = cli.Command{ } func userInfo(c *cli.Context) error { - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/user_list.go b/drone/user/user_list.go similarity index 87% rename from drone/user_list.go rename to drone/user/user_list.go index f827bfa24..e4049aa9c 100644 --- a/drone/user_list.go +++ b/drone/user/user_list.go @@ -1,10 +1,12 @@ -package main +package user import ( "os" "text/template" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var userListCmd = cli.Command{ @@ -21,7 +23,7 @@ var userListCmd = cli.Command{ } func userList(c *cli.Context) error { - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err } diff --git a/drone/user_rm.go b/drone/user/user_rm.go similarity index 80% rename from drone/user_rm.go rename to drone/user/user_rm.go index 60d94f3d2..9979c2b99 100644 --- a/drone/user_rm.go +++ b/drone/user/user_rm.go @@ -1,9 +1,11 @@ -package main +package user import ( "fmt" "github.com/urfave/cli" + + "github.com/drone/drone/drone/internal" ) var userRemoveCmd = cli.Command{ @@ -15,7 +17,7 @@ var userRemoveCmd = cli.Command{ func userRemove(c *cli.Context) error { login := c.Args().First() - client, err := newClient(c) + client, err := internal.NewClient(c) if err != nil { return err }