-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
239 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path" | ||
"strings" | ||
|
||
sh "github.com/codeskyblue/go-sh" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func getRepoInfo() (user, repo string, err error) { | ||
remoteURL, err := sh.Command( | ||
"git", "config", "--get", "remote.origin.url").Output() | ||
if err != nil { | ||
return | ||
} | ||
urlAndUser, repo := path.Split(string(remoteURL)) | ||
|
||
// get the user or org name | ||
user = path.Base(strings.Replace(urlAndUser, ":", "/", -1)) | ||
|
||
// trim and remove .git extension, if present | ||
repo = strings.TrimSuffix(strings.TrimSpace(repo), ".git") | ||
|
||
return | ||
} | ||
|
||
func addExperiment(templateType string, templateName string, folder string) { | ||
checkTemplateFolderExists(templateType) | ||
|
||
if sh.Test("dir", folder) { | ||
log.Fatalln("Folder " + folder + " already exists.") | ||
} | ||
|
||
template := popperFolder + "/templates/" + templateType + "/" + templateName | ||
|
||
if _, err := sh.Command("cp", "-r", template, folder).CombinedOutput(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
var addCmd = &cobra.Command{ | ||
Use: "add <experiment> [<name>]", | ||
Short: "Add an experiment to the project", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
expname := "" | ||
if len(args) == 1 { | ||
expname = args[0] | ||
} else if len(args) == 2 { | ||
expname = args[1] | ||
} else { | ||
log.Fatalln("Incorrect number of arguments, type 'popper experiment add --help'") | ||
} | ||
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 { | ||
addExperiment("experiments", args[0], "experiments/"+expname) | ||
} | ||
|
||
fmt.Println("Added " + expname + " to experiments/ folder.") | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(addCmd) | ||
} |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
sh "github.com/codeskyblue/go-sh" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func checkTemplateFolderExists(templateType string) { | ||
if !sh.Test("dir", popperFolder+"/templates/"+templateType) { | ||
log.Fatalln("Can't find '" + popperFolder + "/templates/" + templateType + "'." + | ||
"This command must be executed from the project's root folder.") | ||
} | ||
} | ||
|
||
func showExperimentInfo(experimentName string) { | ||
checkTemplateFolderExists("experiments") | ||
if err := sh.Command("cat", popperFolder+"/templates/experiments/"+experimentName+"/README.md").Run(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
var infoCmd = &cobra.Command{ | ||
Use: "info <name>", | ||
Short: "Show information about an experiment.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 1 { | ||
log.Fatalln("This command takes name of experiment as argument.") | ||
} | ||
showExperimentInfo(args[0]) | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(infoCmd) | ||
} |
Oops, something went wrong.