Skip to content
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
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions generic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/git-pkgs/managers/definitions"
)

const argPackage = "package"

type GenericManager struct {
def *definitions.Definition
dir string
Expand Down Expand Up @@ -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,
Expand All @@ -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{},
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{},
}
Expand Down
11 changes: 6 additions & 5 deletions policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down