-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fwslash/download-command'
- Loading branch information
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
go build -o out/exercism exercism/main.go | ||
|
||
set -e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/exercism/cli/api" | ||
"github.com/exercism/cli/config" | ||
) | ||
|
||
// Download returns specified submissions and related problem. | ||
func Download(ctx *cli.Context) { | ||
c, err := config.Read(ctx.GlobalString("config")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
args := ctx.Args() | ||
|
||
if len(args) != 1 { | ||
msg := "Usage: exercism download SUBMISSION_ID" | ||
log.Fatal(msg) | ||
} | ||
|
||
var url string | ||
url = fmt.Sprintf("%s/api/v1/submissions/%s", c.API, args[0]) | ||
|
||
submission, err := api.Download(url) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var path string | ||
|
||
path = filepath.Join(c.Dir, "solutions", submission.Username, submission.Language, submission.Slug, args[0]) | ||
|
||
if err := os.MkdirAll(path, 0755); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for name, contents := range submission.ProblemFiles { | ||
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, name), []byte(contents), 0755); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
for name, contents := range submission.SolutionFiles { | ||
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, name), []byte(contents), 0755); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
fmt.Printf("Successfully downloaded submission.\n\nThe submission can be viewed at:\n %s\n\n", path) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters