Skip to content

Commit

Permalink
feat(doggo): Setup flag that only creates a nick and displays it
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Dec 20, 2019
1 parent cb639f3 commit a75e2d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ including all your datasets, and de-registers your peername from the registry.`,
cmd.Flags().StringVarP(&o.Peername, "peername", "", "", "choose your desired peername")
cmd.Flags().StringVarP(&o.IPFSConfigData, "ipfs-config", "", "", "json-encoded configuration data, specify a filepath with '@' prefix")
cmd.Flags().StringVarP(&o.ConfigData, "config-data", "", "", "json-encoded configuration data, specify a filepath with '@' prefix")
cmd.Flags().BoolVar(&o.GimmeDoggo, "gimme-doggo", false, "create and display a doggo name only")

return cmd
}
Expand All @@ -74,6 +75,7 @@ type SetupOptions struct {
Registry string
IPFSConfigData string
ConfigData string
GimmeDoggo bool

QriRepoPath string
IpfsFsPath string
Expand All @@ -90,6 +92,10 @@ func (o *SetupOptions) Complete(f Factory, args []string) (err error) {

// Run executes the setup command
func (o *SetupOptions) Run(f Factory) error {
if o.GimmeDoggo {
return o.CreateAndDisplayDoggo()
}

if o.Remove {
cfg, err := f.Config()
if err != nil {
Expand Down Expand Up @@ -207,6 +213,14 @@ func (o *SetupOptions) DoSetup(f Factory) (err error) {
return f.Init()
}

// CreateAndDisplayDoggo creates and display a doggo name
func (o *SetupOptions) CreateAndDisplayDoggo() error {
_, peerID := o.Generator.GeneratePrivateKeyAndPeerID()
dognick := o.Generator.GenerateNickname(peerID)
printSuccess(o.Out, dognick)
return nil
}

// QRIRepoInitialized checks to see if a repository has been initialized at $QRI_PATH
func QRIRepoInitialized(path string) bool {
// for now this just checks for an existing config file
Expand Down
11 changes: 11 additions & 0 deletions cmd/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/qri-io/ioes"
)

Expand All @@ -22,3 +23,13 @@ func TestSetupComplete(t *testing.T) {

opt.Complete(f, nil)
}

func TestSetupGimmeDoggo(t *testing.T) {
run := NewTestRunner(t, "test_peer", "")

actual := run.MustExec(t, "qri setup --gimme-doggo")
expect := "testnick\n"
if diff := cmp.Diff(expect, actual); diff != "" {
t.Errorf("unexpected (-want +got):\n%s", diff)
}
}

0 comments on commit a75e2d0

Please sign in to comment.