diff --git a/definitions/schema.go b/definitions/schema.go index ed96b56..08d342b 100644 --- a/definitions/schema.go +++ b/definitions/schema.go @@ -56,13 +56,14 @@ type Extract struct { } type Arg struct { - Position int `yaml:"position"` - Required bool `yaml:"required"` - Validate string `yaml:"validate,omitempty"` - Flag string `yaml:"flag,omitempty"` - Suffix string `yaml:"suffix,omitempty"` // append user value with this prefix, e.g. "@" for pkg@version - FixedSuffix string `yaml:"fixed_suffix,omitempty"` // always append this suffix, e.g. "@none" for go remove - ExtractionOnly bool `yaml:"extraction_only,omitempty"` // arg is only used for output extraction, not passed to command + Position int `yaml:"position"` + Required bool `yaml:"required"` + Validate string `yaml:"validate,omitempty"` + Flag string `yaml:"flag,omitempty"` + Suffix string `yaml:"suffix,omitempty"` // append user value with this prefix, e.g. "@" for pkg@version + FixedSuffix string `yaml:"fixed_suffix,omitempty"` // always append this suffix, e.g. "@none" for go remove + ExtractionOnly bool `yaml:"extraction_only,omitempty"` // arg is only used for output extraction, not passed to command + SuppressDefaultFlags bool `yaml:"suppresses_default_flags,omitempty"` // if this arg is passed, then we want to skip default flags } type Flag struct { diff --git a/definitions/uv.yaml b/definitions/uv.yaml index 2aadf60..fe0f203 100644 --- a/definitions/uv.yaml +++ b/definitions/uv.yaml @@ -106,7 +106,11 @@ commands: update: base: [sync] args: - package: {position: 0, required: false, validate: pypi_package} + package: + required: false + validate: pypi_package + flag: "--upgrade-package" + suppresses_default_flags: true flags: quiet: [--quiet] default_flags: [--upgrade] diff --git a/translator.go b/translator.go index cbd0449..54cfc86 100644 --- a/translator.go +++ b/translator.go @@ -89,6 +89,8 @@ func (t *Translator) buildCommandChain(binary string, cmd definitions.Command, i func (t *Translator) buildSingleCommand(binary string, cmd definitions.Command, input CommandInput) ([]string, error) { args := []string{binary} + suppressDefaultFlags := false + baseOverrideUsed := t.applyBaseOverrides(&args, cmd, input) packageVal := input.Args["package"] @@ -103,11 +105,16 @@ func (t *Translator) buildSingleCommand(binary string, cmd definitions.Command, if val == "" { continue } + if entry.argDef.SuppressDefaultFlags { + suppressDefaultFlags = true + } } t.applyVersionSuffix(&args, cmd, input, packageVal) - args = append(args, cmd.DefaultFlags...) + if !suppressDefaultFlags { + args = append(args, cmd.DefaultFlags...) + } t.applyUserFlags(&args, cmd, input, baseOverrideUsed) diff --git a/translator_test.go b/translator_test.go index 3fc45e2..3477002 100644 --- a/translator_test.go +++ b/translator_test.go @@ -713,6 +713,20 @@ func TestUvUpdate(t *testing.T) { } } +func TestUvUpdatePackage(t *testing.T) { + tr := loadTranslator(t) + cmd, err := tr.BuildCommand("uv", "update", CommandInput{ + Args: map[string]string{"package": "requests"}, + }) + if err != nil { + t.Fatalf("BuildCommand failed: %v", err) + } + expected := []string{"uv", "sync", "--upgrade-package", "requests"} + if !reflect.DeepEqual(cmd, expected) { + t.Errorf("got %v, want %v", cmd, expected) + } +} + // --- yarn tests --- func TestYarnInstall(t *testing.T) {