Skip to content

Commit

Permalink
[#200] Make functions in vcs/command.go public
Browse files Browse the repository at this point in the history
To be able to isolate git related code in their own subpackage
- rename
- adapt call sites
  • Loading branch information
philou authored and mengdaming committed Jan 2, 2023
1 parent 4a8bcf5 commit 71273d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/vcs/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ package vcs

import "os/exec"

func isCommandAvailable(command string) bool {
// IsCommandAvailable indicates if the provided command is available in the path
func IsCommandAvailable(command string) bool {
_, err := exec.LookPath(command)
return err == nil
}

func getCommandPath(command string) string {
// GetCommandPath returns the full path to the provided command
func GetCommandPath(command string) string {
path, _ := exec.LookPath(command)
return path
}
8 changes: 4 additions & 4 deletions src/vcs/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ import (
)

func Test_check_command_is_available_for_a_valid_command(t *testing.T) {
assert.True(t, isCommandAvailable("ls"))
assert.True(t, IsCommandAvailable("ls"))
}

func Test_check_command_is_available_for_an_invalid_command(t *testing.T) {
assert.False(t, isCommandAvailable("unknown-command"))
assert.False(t, IsCommandAvailable("unknown-command"))
}

func Test_check_command_path_for_a_valid_command(t *testing.T) {
base := filepath.Base(getCommandPath("ls"))
base := filepath.Base(GetCommandPath("ls"))
assert.Equal(t, strings.TrimSuffix(base, ".exe"), "ls")
}

func Test_check_command_path_for_an_invalid_command(t *testing.T) {
assert.Zero(t, getCommandPath("unknown-command"))
assert.Zero(t, GetCommandPath("unknown-command"))
}
4 changes: 2 additions & 2 deletions src/vcs/git_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (

// IsGitCommandAvailable indicates if git command is available on local machine
func IsGitCommandAvailable() bool {
return isCommandAvailable("git")
return IsCommandAvailable("git")
}

// GetGitCommandPath returns the path to git command on this machine
func GetGitCommandPath() string {
return getCommandPath("git")
return GetCommandPath("git")
}

// GetGitCommandVersion returns the version of git command on this machine
Expand Down

0 comments on commit 71273d5

Please sign in to comment.