Skip to content

Commit

Permalink
Creates .popper.yml configuration file
Browse files Browse the repository at this point in the history
fixes #159
  • Loading branch information
ivotron committed Oct 9, 2017
1 parent 9decf05 commit 157b219
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
5 changes: 5 additions & 0 deletions popper/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ var addCmd = &cobra.Command{
if !sh.Test("dir", ".git") {
log.Fatalln("Can't find .git folder. Are you on the root folder of project?")
}

if strings.HasPrefix(args[0], "paper-") {
addExperiment("paper", args[0], "paper/")
} else {
// create experiments folder if it doesn't exist
if err := sh.Command("mkdir", "-p", "experiments/").Run(); err != nil {
log.Fatalln(err)
}
addExperiment("experiments", args[0], "experiments/"+expname)
}

Expand Down
28 changes: 20 additions & 8 deletions popper/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,31 @@ func initExperiment(name string) {
}

var initCmd = &cobra.Command{
Use: "init <name>",
Short: "Initializes an experiment or paper folder.",
Long: `Initializes an experiment or paper folder. If the given name is 'paper',
then a 'paper' folder is created. Otherwise, an experiment named 'name'
is created.`,
Use: "init [<name>]",
Short: "Initializes a repository, experiment or paper folder.",
Long: `Without any arguments, this command initializes a popper repository. If
an argument is given, an experiment or paper folder is initialized. If the given
name is 'paper', then a 'paper' folder is created. Otherwise, an experiment named
'name' is created.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalln("This command takes one argument.")
if len(args) > 1 {
log.Fatalln("This command takes one argument at most.")
}
if !sh.Test("dir", ".git") {
log.Fatalln("Can't find .git folder. Are you on the root folder of project?")
}
initExperiment(args[0])
if len(args) == 0 {
if sh.Test("file", ".popper.yml") {
log.Fatalln("File .popper.yml already exists")
}
err := ioutil.WriteFile(".popper.yml", []byte(""), 0644)
if err != nil {
log.Fatalln(err)
}
fmt.Println("Initialized popper repository.")
} else {
initExperiment(args[0])
}
},
}

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.1"
var versionId = "0.5-dev"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down

0 comments on commit 157b219

Please sign in to comment.