Add possiblity to limit actions to tagged or named repository
This commit is contained in:
parent
5c98ab6554
commit
23e4547e52
11 changed files with 345 additions and 24 deletions
|
|
@ -40,6 +40,14 @@ func ParseCliArguments(name, description string, arguments []string) (CliArgumen
|
|||
Help: "Turn off color printing",
|
||||
})
|
||||
|
||||
limitName := parser.String("n", "name", &argparse.Options{
|
||||
Help: "Limit action to the specified repository name",
|
||||
})
|
||||
|
||||
limitTags := parser.StringList("t", "tag", &argparse.Options{
|
||||
Help: "Limit actions to repositories that contain specific tags",
|
||||
})
|
||||
|
||||
if err := parser.Parse(arguments); err != nil {
|
||||
return CliArguments{}, errors.New(parser.Usage("Please follow this help"))
|
||||
}
|
||||
|
|
@ -48,11 +56,17 @@ func ParseCliArguments(name, description string, arguments []string) (CliArgumen
|
|||
return CliArguments{}, errors.New(errNoCommand)
|
||||
}
|
||||
|
||||
if *limitName != "" && len(*limitTags) != 0 {
|
||||
return CliArguments{}, errors.New(errNameAndTagsTogether)
|
||||
}
|
||||
|
||||
return CliArguments{
|
||||
ConfigurationFile: *configFile,
|
||||
Sync: syncCMD.Happened(),
|
||||
Status: statusCMD.Happened(),
|
||||
Version: *version,
|
||||
Color: !(*color),
|
||||
LimitName: *limitName,
|
||||
LimitTags: *limitTags,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,22 @@ func TestParsingDefaultArguments(t *testing.T) {
|
|||
|
||||
func TestParsingWithoutCommand(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName", "--name", "test"}
|
||||
|
||||
results, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, not results: %v", results)
|
||||
}
|
||||
if err.Error() != errNoCommand {
|
||||
t.Errorf("Expected to get \"%v\", instead of this got \"%v\"", errNoCommand, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestParsingNothingProvided(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName"}
|
||||
|
||||
|
|
@ -49,3 +65,19 @@ func TestParsingWithoutCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
func TestParsingNameAndTags(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName", "status", "--tag", "example", "--name", "example"}
|
||||
|
||||
results, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, not results: %v", results)
|
||||
}
|
||||
|
||||
if err.Error() != errNameAndTagsTogether {
|
||||
t.Errorf("Expected to get \"%v\", instead of this got \"%v\"", errNameAndTagsTogether, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ repositories:
|
|||
dest: "example/path"
|
||||
name: "custom_example"
|
||||
- src: https://github.com/example/example2.git
|
||||
tags:
|
||||
- "example"
|
||||
`)
|
||||
|
||||
homedir, _ := os.UserHomeDir()
|
||||
|
|
@ -43,6 +45,7 @@ repositories:
|
|||
Name: "example2",
|
||||
Src: "https://github.com/example/example2.git",
|
||||
Dest: "example2",
|
||||
Tags: []string{"example"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -12,6 +11,7 @@ const (
|
|||
errNotSupportedType = "not supported configuration type"
|
||||
errMissingWorkspaceField = "missing required \"workspace\" field"
|
||||
errMissingSrcField = "missing required field the \"src\" in row %v"
|
||||
errNameAndTagsTogether = "name and tags arguments connot be used together"
|
||||
)
|
||||
|
||||
func getDuplicateFieldError(field string, name string, rows []int) error {
|
||||
|
|
@ -21,7 +21,5 @@ func getDuplicateFieldError(field string, name string, rows []int) error {
|
|||
rowsInString = append(rowsInString, strconv.Itoa(row))
|
||||
}
|
||||
|
||||
errorMessage := fmt.Sprintf("The %v \"%v\" is duplicated in rows: %v", field, name, strings.Join(rowsInString, ","))
|
||||
|
||||
return errors.New(errorMessage)
|
||||
return fmt.Errorf("the %v \"%v\" is duplicated in rows: %v", field, name, strings.Join(rowsInString, ","))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ type Configuration struct {
|
|||
}
|
||||
|
||||
type RepositoryConfig struct {
|
||||
Name string `yaml:",omitempty"`
|
||||
Src string `yaml:",omitempty"`
|
||||
Dest string `yaml:",omitempty"`
|
||||
Name string `yaml:",omitempty"`
|
||||
Src string `yaml:",omitempty"`
|
||||
Dest string `yaml:",omitempty"`
|
||||
Tags []string `yaml:",omitempty"`
|
||||
}
|
||||
|
||||
type CliArguments struct {
|
||||
|
|
@ -17,4 +18,6 @@ type CliArguments struct {
|
|||
Status bool
|
||||
Version bool
|
||||
Color bool
|
||||
LimitName string
|
||||
LimitTags []string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue