Skip to content

Commit

Permalink
fix #314: --version not showing lab version
Browse files Browse the repository at this point in the history
  • Loading branch information
zaquestion committed Oct 25, 2019
1 parent 45bb615 commit 2ae2195
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
- linux

go:
- 1.11.x
- 1.13.x

# use containers which run faster and have cache
sudo: false
Expand Down
6 changes: 4 additions & 2 deletions cmd/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions cmd/project_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"))
Expand Down
11 changes: 6 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snippet_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/snippet_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand Down
1 change: 1 addition & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(".", "_"))
Expand Down

0 comments on commit 2ae2195

Please sign in to comment.