-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
7 changed files
with
79 additions
and
60 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,60 @@ | ||
package flags | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"html/template" | ||
"os" | ||
"path" | ||
) | ||
|
||
const ( | ||
GithubCredentialsKey = "M2T_GITHUB" | ||
// GitlabsCredentialsKey = "M2T_GITLAB" | ||
LookupGithubTagsKey = "M2T_GHTAGS" | ||
OfflineKey = "M2T_OFFLINE" | ||
PrefixKey = "M2T_PREFIX" | ||
) | ||
|
||
var ( | ||
LookupGithubTags = os.Getenv(LookupGithubTagsKey) == "1" | ||
Offline = os.Getenv(OfflineKey) == "1" | ||
PackagePrefix = os.Getenv(PrefixKey) | ||
ShowVersion = false | ||
) | ||
|
||
var helpTemplate = template.Must(template.New("help").Parse(` | ||
Vendor package dependencies and then run {{.Name}} on vendor/modules.txt: | ||
$ go mod vendor | ||
$ {{.Name}} vendor/modules.txt | ||
By default, generated GH_TUPLE entries will place packages under "vendor". | ||
This can be changed by passing different prefix using -prefix option (e.g. | ||
-prefix src). | ||
When generating GL_TUPLE entries, modules2tuple will attempt to use Gitlab | ||
API to resolve short commit IDs and tags to the full 40-character IDs as | ||
required by bsd.sites.mk. If network access is not available or not wanted, | ||
this commit ID translation can be disabled with -offline flag. | ||
`)) | ||
|
||
func init() { | ||
basename := path.Base(os.Args[0]) | ||
if PackagePrefix == "" { | ||
PackagePrefix = "vendor" | ||
} | ||
|
||
flag.BoolVar(&LookupGithubTags, "ghtags", LookupGithubTags, fmt.Sprintf("lookup tags with Github API (env %s)", LookupGithubTagsKey)) | ||
flag.BoolVar(&Offline, "offline", Offline, fmt.Sprintf("disable all network access (env %s)", OfflineKey)) | ||
flag.StringVar(&PackagePrefix, "prefix", PackagePrefix, fmt.Sprintf("package prefix (env %s)", PrefixKey)) | ||
flag.BoolVar(&ShowVersion, "v", false, "show version") | ||
|
||
flag.Usage = func() { | ||
fmt.Fprintf(os.Stderr, "Usage: %s [options] modules.txt\n", basename) | ||
flag.PrintDefaults() | ||
helpTemplate.Execute(os.Stderr, map[string]string{ | ||
"Name": basename, | ||
}) | ||
} | ||
} |
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