Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple attributes in CLI flag via comma-separated list
- Loading branch information
Showing
11 changed files
with
279 additions
and
31 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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Attributes []string | ||
|
||
func (attrs *Attributes) String() string { | ||
return fmt.Sprint(*attrs) | ||
} | ||
|
||
// Set is the method to set the flag value, part of the flag.Value interface. | ||
// Set's argument is a string to be parsed to set the flag. | ||
// It's a comma-separated list, so we split it. | ||
func (attrs *Attributes) Set(attributes string) error { | ||
if len(*attrs) > 0 { | ||
return fmt.Errorf("attributes flag already set") | ||
} | ||
|
||
for _, attr := range strings.Split(attributes, ",") { | ||
*attrs = append(*attrs, attr) | ||
} | ||
|
||
return nil | ||
} |
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
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
Oops, something went wrong.