-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the order of arguments is matter
- Loading branch information
Andrey Kontyakov
committed
Mar 30, 2024
1 parent
f682da1
commit f3c204a
Showing
2 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
package factory | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ArgsFromMapToSlice create the slice of args | ||
// Along with that, if a flag doesn't have a value, it's presented barely without a value assignment. | ||
func argsFromMapToSlice(args map[string]string) (slice []string) { | ||
for flag, value := range args { | ||
if len(value) == 0 { | ||
slice = append(slice, flag) | ||
// argsFromSliceToMap transforms a slice of string into a map | ||
func argsFromSliceToMap(args []string) (m map[string]string) { | ||
m = make(map[string]string) | ||
|
||
continue | ||
for _, arg := range args { | ||
parts := strings.SplitN(arg, "=", 2) | ||
|
||
flag, value := parts[0], "" | ||
|
||
if len(parts) > 1 { | ||
value = parts[1] | ||
} | ||
|
||
slice = append(slice, fmt.Sprintf("%s=%s", flag, value)) | ||
m[flag] = value | ||
} | ||
|
||
return slice | ||
return m | ||
} |