mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Modify gorepomod to unpin conditionally.
This commit is contained in:
@@ -37,14 +37,19 @@ Use this to get module names for use in other commands.
|
||||
Creates a change with mechanical updates
|
||||
to `go.mod` and `go.sum` files.
|
||||
|
||||
#### `gorepomod unpin {module}`
|
||||
#### `gorepomod unpin {module} [{conditionalmodule}]`
|
||||
|
||||
Creates a change to `go.mod` files.
|
||||
|
||||
For each module _m_ in the repository,
|
||||
if _m_ depends on a _{module}_,
|
||||
then _m_'s dependency on it will be replaced by
|
||||
a relative path to the in-repo module.
|
||||
if _m_ depends on a _{module}_, then
|
||||
_m_'s dependency on _{module} will be
|
||||
replaced by a relative path to the in-repo
|
||||
version of _{module}_.
|
||||
|
||||
If _conditionalModule_ is specified, then
|
||||
the replacement of _{module}_ will happen
|
||||
if _m_ depends on _{conditionalModule}_.
|
||||
|
||||
#### `gorepomod pin {module} [{version}]`
|
||||
|
||||
|
||||
@@ -51,11 +51,12 @@ const (
|
||||
)
|
||||
|
||||
type Args struct {
|
||||
cmd Command
|
||||
moduleName misc.ModuleShortName
|
||||
version semver.SemVer
|
||||
bump semver.SvBump
|
||||
doIt bool
|
||||
cmd Command
|
||||
moduleName misc.ModuleShortName
|
||||
conditionalModule misc.ModuleShortName
|
||||
version semver.SemVer
|
||||
bump semver.SvBump
|
||||
doIt bool
|
||||
}
|
||||
|
||||
func (a *Args) GetCommand() Command {
|
||||
@@ -74,6 +75,10 @@ func (a *Args) ModuleName() misc.ModuleShortName {
|
||||
return a.moduleName
|
||||
}
|
||||
|
||||
func (a *Args) ConditionalModule() misc.ModuleShortName {
|
||||
return a.conditionalModule
|
||||
}
|
||||
|
||||
func (a *Args) Exclusions() (result []string) {
|
||||
// Make sure the list has no repeats.
|
||||
for k := range utils.SliceToSet(excSlice) {
|
||||
@@ -122,6 +127,7 @@ func Parse() (result *Args, err error) {
|
||||
result.doIt = clArgs.doIt
|
||||
|
||||
result.moduleName = misc.ModuleUnknown
|
||||
result.conditionalModule = misc.ModuleUnknown
|
||||
if !clArgs.more() {
|
||||
return nil, fmt.Errorf("command needs at least one arg")
|
||||
}
|
||||
@@ -146,6 +152,9 @@ func Parse() (result *Args, err error) {
|
||||
return nil, fmt.Errorf("unpin needs a moduleName to unpin")
|
||||
}
|
||||
result.moduleName = misc.ModuleShortName(clArgs.next())
|
||||
if clArgs.more() {
|
||||
result.conditionalModule = misc.ModuleShortName(clArgs.next())
|
||||
}
|
||||
result.cmd = UnPin
|
||||
case cmdTidy:
|
||||
result.cmd = Tidy
|
||||
|
||||
@@ -53,10 +53,17 @@ func (mgr *Manager) Pin(
|
||||
})
|
||||
}
|
||||
|
||||
func (mgr *Manager) UnPin(doIt bool, target misc.LaModule) error {
|
||||
func (mgr *Manager) UnPin(
|
||||
doIt bool, target misc.LaModule, conditional misc.LaModule) error {
|
||||
return mgr.modules.Apply(func(m misc.LaModule) error {
|
||||
if yes, oldVersion := m.DependsOn(target); yes {
|
||||
return edit.New(m, doIt).UnPin(target, oldVersion)
|
||||
if conditional == nil {
|
||||
if yes, oldVersion := m.DependsOn(target); yes {
|
||||
return edit.New(m, doIt).UnPin(target, oldVersion)
|
||||
}
|
||||
} else {
|
||||
if yes, oldVersion := m.DependsOn(conditional); yes {
|
||||
return edit.New(m, doIt).UnPin(target, oldVersion)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -27,25 +27,34 @@ func loadRepoManager(args *arguments.Args) (*repo.Manager, error) {
|
||||
return pr.NewRepoManager(), nil
|
||||
}
|
||||
|
||||
func findModule(
|
||||
name misc.ModuleShortName, mgr *repo.Manager) (m misc.LaModule, err error) {
|
||||
if name != misc.ModuleUnknown {
|
||||
m = mgr.FindModule(name)
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf(
|
||||
"cannot find module %q in repo %s", name, mgr.RepoPath())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func actualMain() error {
|
||||
args, err := arguments.Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mgr, err := loadRepoManager(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var targetModule misc.LaModule = nil
|
||||
if args.ModuleName() != misc.ModuleUnknown {
|
||||
targetModule = mgr.FindModule(args.ModuleName())
|
||||
if targetModule == nil {
|
||||
return fmt.Errorf(
|
||||
"cannot find module %q in repo %s",
|
||||
args.ModuleName(), mgr.RepoPath())
|
||||
}
|
||||
targetModule, err := findModule(args.ModuleName(), mgr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conditionalModule, err := findModule(args.ConditionalModule(), mgr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch args.GetCommand() {
|
||||
@@ -60,7 +69,7 @@ func actualMain() error {
|
||||
}
|
||||
return mgr.Pin(args.DoIt(), targetModule, v)
|
||||
case arguments.UnPin:
|
||||
return mgr.UnPin(args.DoIt(), targetModule)
|
||||
return mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
|
||||
case arguments.Release:
|
||||
return mgr.Release(targetModule, args.Bump(), args.DoIt())
|
||||
case arguments.UnRelease:
|
||||
|
||||
Reference in New Issue
Block a user