-
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.
temp: initial large reorganization and polishing
+ Make as much private as possible. + Split distinct pieces into separate files. + Improve names.
- Loading branch information
1 parent
5c47304
commit 7450a26
Showing
9 changed files
with
199 additions
and
180 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,63 @@ | ||
package cli | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func (app *appEnv) parse(args []string) (string, bool) { | ||
if app.noOp() { | ||
return "", false | ||
} | ||
cmdFlags := flag.NewFlagSet("gitmirror", flag.ContinueOnError) | ||
cmdFlags.SetOutput(io.Discard) | ||
var helpWanted bool | ||
cmdFlags.BoolVar(&helpWanted, "help", false, "") | ||
cmdFlags.BoolVar(&helpWanted, "h", false, "") | ||
cmdFlags.BoolVar(&app.quietWanted, "quiet", false, "") | ||
cmdFlags.BoolVar(&app.quietWanted, "q", false, "") | ||
var configFile string | ||
var configIsDefault bool | ||
cmdFlags.StringVar(&configFile, "config", "", "") | ||
cmdFlags.StringVar(&configFile, "c", "", "") | ||
err := cmdFlags.Parse(args) | ||
switch { | ||
// This must precede all other checks. | ||
case err != nil: | ||
fmt.Fprintf( | ||
os.Stderr, | ||
"%s %s: %s\n%s", | ||
app.cmd, | ||
app.subCmd, | ||
err, | ||
app.usage, | ||
) | ||
app.exitValue = exitFailure | ||
case helpWanted: | ||
fmt.Fprintf( | ||
os.Stderr, | ||
"%s: use 'help' not '-help' or '-h'\n", | ||
app.cmd, | ||
) | ||
fmt.Fprint(os.Stderr, app.usage) | ||
app.exitValue = exitFailure | ||
case configFile == "": | ||
configFile = defaultConfig | ||
configIsDefault = true | ||
} | ||
extraArgs := cmdFlags.Args() | ||
if len(extraArgs) > 0 { | ||
fmt.Fprintf( | ||
os.Stderr, | ||
"%s %s: unrecognized arguments: %+v\n", | ||
app.cmd, | ||
app.subCmd, | ||
extraArgs, | ||
) | ||
fmt.Fprint(os.Stderr, app.usage) | ||
app.exitValue = exitFailure | ||
} | ||
return configFile, configIsDefault | ||
} |
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.