-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Greatly stabilise config flag handling
- Loading branch information
Showing
12 changed files
with
160 additions
and
128 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,64 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/pflag" | ||
) | ||
|
||
// Function to add flags from one set to another | ||
func mergeFromFlagsetInto(from, to *pflag.FlagSet) { | ||
from.VisitAll(func(flag *pflag.Flag) { | ||
to.AddFlag(flag) | ||
}) | ||
} | ||
|
||
func mergeCommonFlagset() { | ||
|
||
InitCommonFlagset() | ||
initLogFlagset() | ||
initDBFlagset() | ||
initP2PFlagset() | ||
initHTTPFlagset() | ||
|
||
mergeFromFlagsetInto(logFlagset, commonFlagset) | ||
mergeFromFlagsetInto(dbFlagset, commonFlagset) | ||
mergeFromFlagsetInto(p2pFlagset, commonFlagset) | ||
mergeFromFlagsetInto(httpFlagset, commonFlagset) | ||
|
||
} | ||
|
||
func ParseCommonFlags(exitOnHelp bool) { | ||
|
||
mergeCommonFlagset() | ||
mergeFromFlagsetInto(commonFlagset, actorFlagset) | ||
|
||
if HelpNeeded() && exitOnHelp { | ||
os.Exit(0) | ||
} | ||
|
||
err = commonFlagset.Parse(os.Args[1:]) | ||
if err != nil { | ||
fmt.Printf("Error parsing common flags: %s", err) | ||
os.Exit(64) // EX_USAGE | ||
} | ||
} | ||
|
||
func ParseActorFlags(exitOnHelp bool) { | ||
|
||
mergeCommonFlagset() | ||
actorFlags() | ||
|
||
mergeFromFlagsetInto(commonFlagset, actorFlagset) | ||
|
||
if HelpNeeded() && exitOnHelp { | ||
os.Exit(0) | ||
} | ||
|
||
err = actorFlagset.Parse(os.Args[1:]) | ||
if err != nil { | ||
fmt.Printf("Error parsing actor flags: %s", err) | ||
os.Exit(64) // EX_USAGE | ||
} | ||
} |
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.