This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b749952
commit f382947
Showing
1 changed file
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package flag | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Setup parses flag and setups usage function. | ||
// `positionalArgs` is a string representing positional args, eg: "arg1 arg2 arg3" | ||
// `commands` if provided is a positional argument command description. | ||
func Setup(version, positionalArgs string, commands ...string) { | ||
Usage = func() { | ||
fmt.Fprintln(os.Stderr, "Version: ", version) | ||
if len(commands) != 0 { | ||
fmt.Fprintf(os.Stderr, | ||
"USAGE: %s <commands> <parameters> %s\n\n", os.Args[0], positionalArgs) | ||
fmt.Fprint(os.Stderr, "COMMANDS:", commands[0], "\n\n") | ||
} else { | ||
fmt.Fprintf(os.Stderr, | ||
"USAGE: %s <parameters> %s\n\n", os.Args[0], positionalArgs) | ||
} | ||
fmt.Fprintln(os.Stderr, "PARAMETERS:") | ||
PrintDefaults() | ||
} | ||
Parse() | ||
} |