Skip to content

Commit

Permalink
cli: adds ci subcommand and ci travis
Browse files Browse the repository at this point in the history
fixes #129
  • Loading branch information
ivotron committed Jul 20, 2017
1 parent 767aa84 commit 65634fd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
6 changes: 0 additions & 6 deletions popper/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ var checkCmd = &cobra.Command{
},
}

func checkWeInExperimentFolder() {
if !sh.Test("dir", "../../experiments") {
log.Fatalln("Not inside an experiment folder, 'cd' into one first.")
}
}

func init() {
RootCmd.AddCommand(checkCmd)

Expand Down
52 changes: 52 additions & 0 deletions popper/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"io/ioutil"
"log"
"github.com/spf13/cobra"
)

var travisYaml = `---
language: python
python:
- '2.7'
services:
- docker
install:
- curl -O https://raw.githubusercontent.com/systemslab/popperci/master/implementations/python/docker/entrypoint.py
- chmod 755 entrypoint.py
script: ./entrypoint.py
`

var ciCmd = &cobra.Command{
Use: "ci",
Short: "Generate config files for a CI system.",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
log.Fatalln("Can't use this subcommand directly. See 'popper help ci' for usage")
},
}
var ciTravisCmd = &cobra.Command{
Use: "travis",
Short: "Generate config file for TravisCI.",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
log.Fatalln("This command does not take arguments.")
}
ensureRootFolder()
err := ioutil.WriteFile("./.travis.yml", []byte(travisYaml), 0755)
if err != nil {
log.Fatalln("Error writing .travis.yml")
}
},
}

func init() {
RootCmd.AddCommand(ciCmd)
ciCmd.AddCommand(ciTravisCmd)
}
12 changes: 12 additions & 0 deletions popper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func getTemplates() (org_repo_branch string, err error) {
return popperRepoUrl, nil
}

func ensureExperimentFolder() {
if !sh.Test("dir", "../../experiments") {
log.Fatalln("Not inside an experiment folder, 'cd' into one first.")
}
}

func ensureRootFolder() {
if !sh.Test("dir", "experiments") {
log.Fatalln("Can't find experiments/ folder in current directory, 'cd' into project root folder first.")
}
}

func init() {
RootCmd.Flags().BoolVarP(
&showVersion, "version", "v", false,
Expand Down
2 changes: 1 addition & 1 deletion popper/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

var versionId = "0.4-dev"
var versionId = "0.4"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
4 changes: 2 additions & 2 deletions popper/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var wsLogCmd = &cobra.Command{
if len(args) > 0 {
log.Fatalln("This command doesn't take arguments.")
}
checkWeInExperimentFolder()
ensureExperimentFolder()
expFolder := getWsExperimentFolderPath()
commitFolders, _ := ioutil.ReadDir(expFolder)
for _, f := range commitFolders {
Expand Down Expand Up @@ -103,7 +103,7 @@ var wsCommitCmd = &cobra.Command{
if len(args) > 0 {
log.Fatalln("This command doesn't take arguments.")
}
checkWeInExperimentFolder()
ensureExperimentFolder()
if _, err := sh.Command("rsync", "--version").CombinedOutput(); err != nil {
log.Fatalln("Can't invoke rsync.")
}
Expand Down

0 comments on commit 65634fd

Please sign in to comment.