diff --git a/.travis.yml b/.travis.yml index 247a6e16..82403fe1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: - linux go: - - 1.11.x + - 1.13.x # use containers which run faster and have cache sudo: false diff --git a/cmd/project_create.go b/cmd/project_create.go index 0651539e..afef6c08 100644 --- a/cmd/project_create.go +++ b/cmd/project_create.go @@ -5,6 +5,7 @@ import ( "log" "strings" + "github.com/davecgh/go-spew/spew" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" "github.com/zaquestion/lab/internal/git" @@ -41,7 +42,7 @@ lab project create -n "new proj" # user/new-proj named "new proj"`, } // set the default visibility - visibility := gitlab.InternalVisibility + visibility := gitlab.PrivateVisibility // now override the visibility if the user passed in relevant flags. if // the user passes multiple flags, this will use the "most private" @@ -66,6 +67,7 @@ lab project create -n "new proj" # user/new-proj named "new proj"`, if err != nil { log.Fatal(err) } + spew.Dump(p) if git.InsideGitRepo() { err = git.RemoteAdd("origin", p.SSHURLToRepo, ".") if err != nil { @@ -97,6 +99,6 @@ func init() { projectCreateCmd.Flags().StringP("description", "d", "", "description of the new project") projectCreateCmd.Flags().BoolVarP(&private, "private", "p", false, "Make project private: visible only to project members") projectCreateCmd.Flags().BoolVar(&public, "public", false, "Make project public: visible without any authentication") - projectCreateCmd.Flags().BoolVar(&internal,"internal", false, "Make project internal: visible to any authenticated user (default)") + projectCreateCmd.Flags().BoolVar(&internal, "internal", false, "Make project internal: visible to any authenticated user (default)") projectCmd.AddCommand(projectCreateCmd) } diff --git a/cmd/project_create_test.go b/cmd/project_create_test.go index 63d2e418..6c10e6c5 100644 --- a/cmd/project_create_test.go +++ b/cmd/project_create_test.go @@ -21,7 +21,7 @@ func Test_projectCreateCmd(t *testing.T) { os.Remove(filepath.Join(repo, ".git/config")) t.Run("create", func(t *testing.T) { - cmd := exec.Command(labBinaryPath, "project", "create") + cmd := exec.Command(labBinaryPath, "project", "create", "-p") cmd.Dir = repo b, err := cmd.CombinedOutput() @@ -42,7 +42,6 @@ func Test_projectCreateCmd(t *testing.T) { } require.Equal(t, "git@gitlab.com:lab-testing/"+expectedPath+".git\n", string(remote)) }) - p, err := lab.FindProject(expectedPath) if err != nil { t.Fatal(errors.Wrap(err, "failed to find project for cleanup")) diff --git a/cmd/root.go b/cmd/root.go index a5ee72fc..7658eb62 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -236,7 +236,7 @@ func Execute() { if forkedFromRemote == "origin" { // Check if the user fork exists - _, err = gitconfig.Local("remote." + lab.User() + ".url") + _, err := gitconfig.Local("remote." + lab.User() + ".url") if err == nil { forkRemote = lab.User() } @@ -287,17 +287,18 @@ func Execute() { // allow flags to the root cmd to be passed through. Technically we'll drop any exit code info which isn't ideal. // TODO: remove for 1.0 when we stop wrapping git if cmd.Use == RootCmd.Use && len(os.Args) > 1 { - var hFlaged bool + var knownFlag bool for _, v := range os.Args { - if v == "--help" { - hFlaged = true + if v == "--help" || v == "--version" { + knownFlag = true } } - if !hFlaged { + if !knownFlag { git.New(os.Args[1:]...).Run() return } } + if err := RootCmd.Execute(); err != nil { // Execute has already logged the error os.Exit(1) diff --git a/cmd/snippet_create.go b/cmd/snippet_create.go index 03af7fb0..c600b659 100644 --- a/cmd/snippet_create.go +++ b/cmd/snippet_create.go @@ -64,7 +64,7 @@ Optionally add a title & description with -m`, log.Fatal("aborting snippet due to empty msg") } - visibility := gitlab.InternalVisibility + visibility := gitlab.PrivateVisibility switch { case private: visibility = gitlab.PrivateVisibility diff --git a/cmd/snippet_create_test.go b/cmd/snippet_create_test.go index 62a3d7b2..a9acf5e6 100644 --- a/cmd/snippet_create_test.go +++ b/cmd/snippet_create_test.go @@ -13,7 +13,7 @@ import ( func Test_snippetCreate(t *testing.T) { t.Parallel() repo := copyTestRepo(t) - cmd := exec.Command(labBinaryPath, "snippet", "create", "lab-testing", + cmd := exec.Command(labBinaryPath, "snippet", "create", "-p", "lab-testing", "-m", "snippet title", "-m", "snippet description") cmd.Dir = repo @@ -50,7 +50,7 @@ func Test_snippetCreate_file(t *testing.T) { t.Fatal(err) } - cmd := exec.Command(labBinaryPath, "snippet", "lab-testing", "testfile", + cmd := exec.Command(labBinaryPath, "snippet", "-p", "lab-testing", "testfile", "-m", "snippet title", "-m", "snippet description") cmd.Dir = repo @@ -68,7 +68,7 @@ func Test_snippetCreate_Global(t *testing.T) { t.Parallel() repo := copyTestRepo(t) - cmd := exec.Command(labBinaryPath, "snippet", "create", "-g", + cmd := exec.Command(labBinaryPath, "snippet", "create", "-p", "-g", "-m", "personal snippet title", "-m", "personal snippet description") diff --git a/internal/git/git.go b/internal/git/git.go index 0e0eebab..3386c26f 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -46,6 +46,7 @@ func New(args ...string) *exec.Cmd { func GitDir() (string, error) { cmd := New("rev-parse", "-q", "--git-dir") cmd.Stdout = nil + cmd.Stderr = nil d, err := cmd.Output() if err != nil { return "", err diff --git a/main.go b/main.go index cc57ab5f..a253a0ab 100644 --- a/main.go +++ b/main.go @@ -37,10 +37,9 @@ func loadConfig() (string, string, string) { viper.AddConfigPath(".") viper.AddConfigPath(confpath) gitDir, err := git.GitDir() - if err != nil { - log.Fatal(err) + if err == nil { + viper.AddConfigPath(gitDir) } - viper.AddConfigPath(gitDir) viper.SetEnvPrefix("LAB") viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))