diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f7dd188 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,25 @@ +version: "2" + +linters: + enable: + - gocritic + - gocognit + - gocyclo + - maintidx + - dupl + - mnd + - unparam + - ireturn + - goconst + - errcheck + settings: + goconst: + ignore-tests: true + exclusions: + rules: + - path: _test\.go + linters: + - dupl + - path: ^docs/examples/ + linters: + - goconst diff --git a/generic_manager.go b/generic_manager.go index 6b40f20..7462122 100644 --- a/generic_manager.go +++ b/generic_manager.go @@ -6,6 +6,8 @@ import ( "github.com/git-pkgs/managers/definitions" ) +const argPackage = "package" + type GenericManager struct { def *definitions.Definition dir string @@ -65,7 +67,7 @@ func (m *GenericManager) Install(ctx context.Context, opts InstallOptions) (*Res func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) (*Result, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{ "dev": opts.Dev, @@ -90,7 +92,7 @@ func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) ( func (m *GenericManager) Remove(ctx context.Context, pkg string) (*Result, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{}, } @@ -138,7 +140,7 @@ func (m *GenericManager) Update(ctx context.Context, pkg string) (*Result, error } if pkg != "" { - input.Args["package"] = pkg + input.Args[argPackage] = pkg } cmd, err := m.translator.BuildCommand(m.def.Name, "update", input) @@ -200,7 +202,7 @@ func (m *GenericManager) Resolve(ctx context.Context) (*Result, error) { func (m *GenericManager) Path(ctx context.Context, pkg string) (*PathResult, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{}, } diff --git a/policy.go b/policy.go index 607cafc..d94a038 100644 --- a/policy.go +++ b/policy.go @@ -152,16 +152,17 @@ func (pr *PolicyRunner) Run(ctx context.Context, dir string, args ...string) (*R } // Extract manager and operation from command if possible - if len(args) > 0 { - op.Manager = args[0] + rest := args + if len(rest) > 0 { + op.Manager, rest = rest[0], rest[1:] } - if len(args) > 1 { - op.Operation = args[1] + if len(rest) > 0 { + op.Operation, rest = rest[0], rest[1:] } // Populate Packages from positional args so policies that inspect // package names (e.g. PackageBlocklistPolicy) actually see them when // invoked through the Runner interface. - for _, a := range args[min(2, len(args)):] { + for _, a := range rest { if a == "" || strings.HasPrefix(a, "-") { continue }