Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #314: --version not showing lab version #346

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 Down Expand Up @@ -97,6 +97,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