feat: simplify flag parsing in network plugin

Commands should be written such that they take arguments as is.
This commit is contained in:
Jose Diaz-Gonzalez
2020-05-28 20:30:27 -04:00
parent 94aa67d494
commit 91a668ee8f
3 changed files with 65 additions and 49 deletions

View File

@@ -106,14 +106,20 @@ func CommandList() error {
}
// CommandRebuildall rebuilds network settings for all apps
func CommandRebuildall() {
func CommandRebuildall() error {
apps, err := common.DokkuApps()
if err != nil {
common.LogFail(err.Error())
return err
}
for _, appName := range apps {
BuildConfig(appName)
err = BuildConfig(appName)
if err != nil {
return err
}
}
return nil
}
// CommandReport displays a network report for one or more apps
@@ -140,7 +146,7 @@ func CommandReport(appName string, infoFlag string) error {
}
// CommandSet set or clear a network property for an app
func CommandSet(appName string, property string, value string) {
func CommandSet(appName string, property string, value string) error {
if property == "bind-all-interfaces" && value == "" {
value = "false"
}
@@ -156,13 +162,14 @@ func CommandSet(appName string, property string, value string) {
}
if attachProperites[property] {
if invalidNetworks[value] {
common.LogFail("Invalid network name specified for attach")
return errors.New("Invalid network name specified for attach")
}
if isConflictingPropertyValue(appName, property, value) {
common.LogFail("Network name already associated with this app")
return errors.New("Network name already associated with this app")
}
}
common.CommandPropertySet("network", appName, property, value, DefaultProperties)
return nil
}