-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature:(issue_269) Allow external package flag definitions (#1540)
* Feature:(issue_269) Add compatibility with external package flag definitions * Add tests * Add defer to remove global flag * Use ptr to receiver for extFlag * Add const for flag prefix to ignore
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cli | ||
|
||
import "flag" | ||
|
||
type extFlag struct { | ||
f *flag.Flag | ||
} | ||
|
||
func (e *extFlag) Apply(fs *flag.FlagSet) error { | ||
fs.Var(e.f.Value, e.f.Name, e.f.Usage) | ||
return nil | ||
} | ||
|
||
func (e *extFlag) Names() []string { | ||
return []string{e.f.Name} | ||
} | ||
|
||
func (e *extFlag) IsSet() bool { | ||
return false | ||
} | ||
|
||
func (e *extFlag) String() string { | ||
return FlagStringer(e) | ||
} | ||
|
||
func (e *extFlag) IsVisible() bool { | ||
return true | ||
} | ||
|
||
func (e *extFlag) TakesValue() bool { | ||
return false | ||
} | ||
|
||
func (e *extFlag) GetUsage() string { | ||
return e.f.Usage | ||
} | ||
|
||
func (e *extFlag) GetValue() string { | ||
return e.f.Value.String() | ||
} | ||
|
||
func (e *extFlag) GetDefaultText() string { | ||
return e.f.DefValue | ||
} | ||
|
||
func (e *extFlag) GetEnvVars() []string { | ||
return nil | ||
} |