Skip to content

Commit

Permalink
update CliActions with return value
Browse files Browse the repository at this point in the history
  • Loading branch information
lcowell authored and manusajith committed May 12, 2016
1 parent db595f9 commit 4710640
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Configure stores settings in a JSON file.
// If a setting is not passed as an argument, default
// values are used.
func Configure(ctx *cli.Context) {
func Configure(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -40,4 +40,6 @@ func Configure(ctx *cli.Context) {
fmt.Printf(" --dir=%s\n", c.Dir)
fmt.Printf(" --host=%s\n", c.API)
fmt.Printf(" --api=%s\n\n", c.XAPI)

return nil
}
4 changes: 3 additions & 1 deletion cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type pingResult struct {
}

// Debug provides information about the user's environment and configuration.
func Debug(ctx *cli.Context) {
func Debug(ctx *cli.Context) error {
defer fmt.Printf("\nIf you are having trouble and need to file a GitHub issue (https://github.com/exercism/exercism.io/issues) please include this information (except your API key. Keep that private).\n")

client := &http.Client{Timeout: 20 * time.Second}
Expand Down Expand Up @@ -128,4 +128,6 @@ func Debug(ctx *cli.Context) {
}()

wg.Wait()

return nil
}
4 changes: 3 additions & 1 deletion cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Download returns specified iteration with its related problem.
func Download(ctx *cli.Context) {
func Download(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -53,6 +53,8 @@ func Download(ctx *cli.Context) {

fmt.Printf("Successfully downloaded submission.\n\nThe submission can be viewed at:\n %s\n\n", path)

return nil

}

// writeFile writes the given contents to the given path, creating any necessary parent directories.
Expand Down
5 changes: 4 additions & 1 deletion cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Fetch downloads exercism problems and writes them to disk.
func Fetch(ctx *cli.Context) {
func Fetch(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -54,6 +54,9 @@ func Fetch(ctx *cli.Context) {
}

hw.Summarize(user.HWAll)

return nil
// return cli.NewExitError("no good", 10)
}

func setSubmissionState(problems []*api.Problem, submissionInfo map[string][]api.SubmissionInfo) error {
Expand Down
4 changes: 3 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const msgExplainFetch = "In order to fetch a specific assignment, call the fetch command with a specific assignment.\n\nexercism fetch %s %s\n\n"

// List returns the full list of assignments for a given track.
func List(ctx *cli.Context) {
func List(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand All @@ -40,4 +40,6 @@ func List(ctx *cli.Context) {
}
fmt.Println()
fmt.Printf(msgExplainFetch, trackID, problems[0])

return nil
}
4 changes: 3 additions & 1 deletion cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Open uses the given track and problem and opens it in the browser.
func Open(ctx *cli.Context) {
func Open(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -57,4 +57,6 @@ func Open(ctx *cli.Context) {
if err := cmd.Run(); err != nil {
log.Fatal(err)
}

return nil
}
4 changes: 3 additions & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// Restore returns a user's solved problems.
func Restore(ctx *cli.Context) {
func Restore(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand All @@ -28,4 +28,6 @@ func Restore(ctx *cli.Context) {
log.Fatal(err)
}
hw.Summarize(user.HWNotSubmitted)

return nil
}
4 changes: 3 additions & 1 deletion cmd/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Skip allows a user to skip a specific problem.
func Skip(ctx *cli.Context) {
func Skip(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand All @@ -34,4 +34,6 @@ func Skip(ctx *cli.Context) {
}

fmt.Printf("Exercise %q in %q has been skipped.\n", slug, trackID)

return nil
}
4 changes: 3 additions & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Status is a command that allows a user to view their progress in a given
// language track.
func Status(ctx *cli.Context) {
func Status(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand All @@ -36,4 +36,6 @@ func Status(ctx *cli.Context) {
}

fmt.Println(status)

return nil
}
4 changes: 3 additions & 1 deletion cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Submit posts an iteration to the API.
func Submit(ctx *cli.Context) {
func Submit(ctx *cli.Context) error {
if len(ctx.Args()) == 0 {
log.Fatal("Please enter a file name")
}
Expand Down Expand Up @@ -101,4 +101,6 @@ func Submit(ctx *cli.Context) {

fmt.Printf("Your %s solution for %s has been submitted. View it here:\n%s\n\n", submission.Language, submission.Name, submission.URL)
fmt.Printf("See related solutions and get involved here:\n%stracks/%s/exercises/%s\n\n", c.API, iteration.TrackID, iteration.Problem)

return nil
}
4 changes: 3 additions & 1 deletion cmd/tracks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Tracks lists available tracks.
func Tracks(ctx *cli.Context) {
func Tracks(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
Expand All @@ -35,4 +35,6 @@ Related commands:
exercism list (see 'exercism help list')
`
fmt.Println(msg)

return nil
}
6 changes: 4 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
)

// Upgrade allows the user to upgrade to the latest version of the CLI.
func Upgrade(ctx *cli.Context) {
func Upgrade(ctx *cli.Context) error {
client := http.Client{Timeout: 10 * time.Second}
rel, err := fetchLatestRelease(client)
if err != nil {
Expand All @@ -36,7 +36,7 @@ func Upgrade(ctx *cli.Context) {
// should probably parse semver and compare
if rel.Version() == ctx.App.Version {
fmt.Println("Your CLI is up to date!")
return
return nil
}

// Locate the path to the current `exercism` executable.
Expand Down Expand Up @@ -87,4 +87,6 @@ func Upgrade(ctx *cli.Context) {
}

fmt.Println("Successfully upgraded!")

return nil
}

0 comments on commit 4710640

Please sign in to comment.