Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit e810f9d

Browse files
committed
Specify full repo path with demo init --repo flag
This allows you to create a demo repository in other workspaces as well.
1 parent fb16ace commit e810f9d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

internals/demo/init.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type newClientFunc func() (secrethub.ClientInterface, error)
1919
const defaultDemoRepo = "demo"
2020

2121
type InitCommand struct {
22-
repo string
22+
repo api.RepoPath
2323

2424
io ui.IO
2525
newClient newClientFunc
@@ -35,9 +35,9 @@ func NewInitCommand(io ui.IO, newClient newClientFunc) *InitCommand {
3535
// Register registers the command, arguments and flags on the provided Registerer.
3636
func (cmd *InitCommand) Register(r command.Registerer) {
3737
clause := r.Command("init", "Create the secrets necessary to connect with the demo application.")
38-
clause.HelpLong("The demo init command creates a repository in your personal namespace (called `" + defaultDemoRepo + "` by default). In that repository, it writes the username and password needed to connect to the demo API.")
38+
clause.HelpLong("demo init creates a repository with the username and password needed to connect to the demo API.")
3939

40-
clause.Flag("repo", "The name of the repository to create.").Default(defaultDemoRepo).StringVar(&cmd.repo)
40+
clause.Flag("repo", "The path of the repository to create. Defaults to a "+defaultDemoRepo+" repo in your personal namespace.").SetValue(&cmd.repo)
4141

4242
command.BindAction(clause, cmd.Run)
4343
}
@@ -54,10 +54,13 @@ func (cmd *InitCommand) Run() error {
5454
return err
5555
}
5656

57-
repoPath := secretpath.Join(me.Username, cmd.repo)
57+
repoPath := secretpath.Join(me.Username, defaultDemoRepo)
58+
if cmd.repo != "" {
59+
repoPath = cmd.repo.Value()
60+
}
5861

5962
_, err = client.Repos().Create(repoPath)
60-
if err == api.ErrRepoAlreadyExists && cmd.repo == defaultDemoRepo {
63+
if err == api.ErrRepoAlreadyExists && cmd.repo == "" {
6164
return errors.New("demo repo already exists, use --repo to specify another repo to use")
6265
} else if err != nil {
6366
return err

0 commit comments

Comments
 (0)