1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-23 01:11:57 +01:00

added environment command

This commit is contained in:
Brad Rydzewski 2020-11-16 15:42:23 -05:00
parent bed84a32ff
commit a63407a203
2 changed files with 106 additions and 1 deletions

@ -0,0 +1,103 @@
package environ
import (
"context"
"fmt"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/environ"
"github.com/urfave/cli"
)
// Command exports the admission command set.
var Command = cli.Command{
Name: "env",
Usage: "test env extensions",
Action: environAction,
Flags: []cli.Flag{
//
// build and repository details
//
cli.StringFlag{
Name: "ref",
Usage: "git reference",
Value: "refs/heads/master",
},
cli.StringFlag{
Name: "source",
Usage: "source branch",
Value: "master",
},
cli.StringFlag{
Name: "target",
Usage: "target branch",
Value: "master",
},
cli.StringFlag{
Name: "before",
Usage: "commit sha before the change",
},
cli.StringFlag{
Name: "after",
Usage: "commit sha after the change",
},
cli.StringFlag{
Name: "repository",
Usage: "repository name",
},
cli.StringFlag{
Name: "endpoint",
Usage: "plugin endpoint",
EnvVar: "DRONE_ENVIRON_ENDPOINT",
},
cli.StringFlag{
Name: "secret",
Usage: "plugin secret",
EnvVar: "DRONE_ENVIRON_SECRET",
},
cli.StringFlag{
Name: "ssl-skip-verify",
Usage: "plugin ssl verification disabled",
EnvVar: "DRONE_ENVIRON_SKIP_VERIFY",
},
},
}
func environAction(c *cli.Context) error {
slug := c.String("repository")
owner, name, _ := internal.ParseRepo(slug)
req := &environ.Request{
Repo: drone.Repo{
Namespace: owner,
Name: name,
Slug: slug,
},
Build: drone.Build{
Ref: c.String("ref"),
Before: c.String("before"),
After: c.String("after"),
Source: c.String("source"),
Target: c.String("target"),
},
}
client := environ.Client(
c.String("endpoint"),
c.String("secret"),
c.Bool("ssl-skip-verify"),
)
list, err := client.List(context.Background(), req)
if err != nil {
return err
}
for k, v := range list {
fmt.Printf("%s=%s\n", k, v)
}
return nil
}

@ -4,6 +4,7 @@ import (
"github.com/drone/drone-cli/drone/plugins/admit"
"github.com/drone/drone-cli/drone/plugins/config"
"github.com/drone/drone-cli/drone/plugins/convert"
"github.com/drone/drone-cli/drone/plugins/environ"
"github.com/drone/drone-cli/drone/plugins/registry"
"github.com/drone/drone-cli/drone/plugins/secret"
@ -18,7 +19,8 @@ var Command = cli.Command{
admit.Command,
config.Command,
convert.Command,
secret.Command,
environ.Command,
registry.Command,
secret.Command,
},
}