woodpecker/cli/secret/secret.go
Lauris BH 366a1e18f3
Add cli support for global and organization secrets (#1113)
* Add cli support for global and organization secrets

* Fix usage of deprecated functions
2022-08-15 20:10:13 +02:00

46 lines
986 B
Go

package secret
import (
"strings"
"github.com/urfave/cli/v2"
"github.com/woodpecker-ci/woodpecker/cli/common"
"github.com/woodpecker-ci/woodpecker/cli/internal"
)
// Command exports the secret command.
var Command = &cli.Command{
Name: "secret",
Usage: "manage secrets",
Flags: common.GlobalFlags,
Subcommands: []*cli.Command{
secretCreateCmd,
secretDeleteCmd,
secretUpdateCmd,
secretInfoCmd,
secretListCmd,
},
}
func parseTargetArgs(c *cli.Context) (global bool, owner, name string, err error) {
if c.Bool("global") {
return true, "", "", nil
}
orgName := c.String("organization")
repoName := c.String("repository")
if orgName == "" && repoName == "" {
repoName = c.Args().First()
}
if orgName == "" && !strings.Contains(repoName, "/") {
orgName = repoName
}
if orgName != "" {
return false, orgName, "", err
}
owner, name, err = internal.ParseRepo(repoName)
if err != nil {
return false, "", "", err
}
return false, owner, name, nil
}