Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ const msgWelcomePleaseConfigure = `
%s configure --token=YOUR_TOKEN

`

// Running configure without any arguments will attempt to
// set the default workspace. If the default workspace directory
// risks clobbering an existing directory, it will print an
// error message that explains how to proceed.
const msgRerunConfigure = `

Please re-run the configure command to define where
to download the exercises.

%s configure
`
3 changes: 3 additions & 0 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func runDownload(cfg config.Configuration, flags *pflag.FlagSet, args []string)
tokenURL := config.InferSiteURL(usrCfg.GetString("apibaseurl")) + "/my/settings"
return fmt.Errorf(msgWelcomePleaseConfigure, tokenURL, BinaryName)
}
if usrCfg.GetString("workspace") == "" || usrCfg.GetString("apibaseurl") == "" {
return fmt.Errorf(msgRerunConfigure, BinaryName)
}

uuid, err := flags.GetString("uuid")
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,38 @@ func TestDownloadWithoutToken(t *testing.T) {
}
}

func TestDownloadWithoutWorkspace(t *testing.T) {
v := viper.New()
v.Set("token", "abc123")
cfg := config.Configuration{
UserViperConfig: v,
}

err := runDownload(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{})
if assert.Error(t, err) {
assert.Regexp(t, "re-run the configure", err.Error())
}
}

func TestDownloadWithoutBaseURL(t *testing.T) {
v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", "/home/whatever")
cfg := config.Configuration{
UserViperConfig: v,
}

err := runDownload(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{})
if assert.Error(t, err) {
assert.Regexp(t, "re-run the configure", err.Error())
}
}

func TestDownloadWithoutFlags(t *testing.T) {
v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", "/home/username")
v.Set("apibaseurl", "http://example.com")

cfg := config.Configuration{
UserViperConfig: v,
Expand Down
13 changes: 1 addition & 12 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,7 @@ func runSubmit(cfg config.Configuration, flags *pflag.FlagSet, args []string) er
}

if usrCfg.GetString("workspace") == "" {
// Running configure without any arguments will attempt to
// set the default workspace. If the default workspace directory
// risks clobbering an existing directory, it will print an
// error message that explains how to proceed.
msg := `

Please re-run the configure command to define where
to download the exercises.

%s configure
`
return fmt.Errorf(msg, BinaryName)
return fmt.Errorf(msgRerunConfigure, BinaryName)
}

for i, arg := range args {
Expand Down