diff --git a/README.md b/README.md index eeae219..9890f0a 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ You may pass additional flags to `gi_gen`. These are the currently available fla | `-languages` \| `-l` | List the languages you want to use as templates.
To add multiple templates, use commas as separators, e.g.: `-languages Node,Python` | | `-auto-discover` \| `-d` | Use auto-discovery for project, detecting the project type and using the result as the pre-selected template list. | | `-clean-output` \| `-c` | Perform cleanup on the output .gitignore file, removing any unused patterns | +| `-keep-output` \| `-k` | Do not perform cleanup on the output .gitignore file, keep all the original contents | | `-append` \| `-a` | Append to .gitignore file if it already exists | | `-overwrite` \| `-w` | Overwrite .gitignore file if it already exists | | `-detect-languages` | Outputs the automatically-detected languages, separated by newlines, and exits. Useful for outside tools detection. | diff --git a/cmd/gi_gen.go b/cmd/gi_gen.go index 06830fc..85bfe1c 100644 --- a/cmd/gi_gen.go +++ b/cmd/gi_gen.go @@ -29,13 +29,15 @@ func RunMainCmd() { flagLangs := getLangsFromArgs() internal.GIGen(&internal.GIGenOptions{ Languages: &flagLangs, - AutoDiscover: &autoDiscover, + AutoDiscover: autoDiscover, AutoDiscoverUsed: isFlagPassed("auto-discover") || isFlagPassed("d"), - CleanOutput: &cleanOutput, + CleanOutput: cleanOutput, CleanOutputUsed: isFlagPassed("clean-output") || isFlagPassed("c"), - OverwriteFile: &overwriteFile, + KeepOutput: keepOutput, + KeepOutputUsed: isFlagPassed("keep-output") || isFlagPassed("k"), + OverwriteFile: overwriteFile, OverwriteFileUsed: isFlagPassed("overwrite") || isFlagPassed("w"), - AppendFile: &appendFile, + AppendFile: appendFile, AppendFileUsed: isFlagPassed("append") || isFlagPassed("a"), }) } @@ -43,6 +45,7 @@ func RunMainCmd() { var langsRaw string = "" var cleanCache bool var cleanOutput bool +var keepOutput bool var overwriteFile bool var appendFile bool var detectLanguage bool @@ -59,6 +62,8 @@ func initFlags() { autoDiscoverUsage := "Use auto-discovery for project, detecting the project type and using the result as the pre-" + "selected template list." cleanOutputUsage := "Perform cleanup on the output .gitignore file, removing any unused patterns" + keepOutputUsage := "Do not perform cleanup on the output .gitignore file, keep all the original contents " + + "(opposite of -clean-output)" appendUsage := "Append to .gitignore file if it already exists" overwriteUsage := "Overwrite .gitignore file if it already exists" clearCacheUsage := "Clear the .gitignore cache directory, for troubleshooting or for removing trace files of this " + @@ -75,6 +80,9 @@ func initFlags() { flag.BoolVar(&cleanOutput, "c", false, shorthand(cleanOutputUsage)) flag.BoolVar(&cleanOutput, "clean-output", false, cleanOutputUsage) + flag.BoolVar(&keepOutput, "k", false, shorthand(keepOutputUsage)) + flag.BoolVar(&keepOutput, "keep-output", false, keepOutputUsage) + flag.BoolVar(&overwriteFile, "w", false, shorthand(overwriteUsage)) flag.BoolVar(&overwriteFile, "overwrite", false, overwriteUsage) diff --git a/internal/core.go b/internal/core.go index e7f8602..403ae2d 100644 --- a/internal/core.go +++ b/internal/core.go @@ -12,13 +12,15 @@ import ( type GIGenOptions struct { Languages *[]string - CleanOutput *bool + CleanOutput bool CleanOutputUsed bool - AutoDiscover *bool + KeepOutput bool + KeepOutputUsed bool + AutoDiscover bool AutoDiscoverUsed bool - OverwriteFile *bool + OverwriteFile bool OverwriteFileUsed bool - AppendFile *bool + AppendFile bool AppendFileUsed bool } @@ -80,8 +82,8 @@ func processFileOutput(cleanupSelection bool, selectedContents []string, selecte func getCleanupSelection(opts GIGenOptions) bool { var cleanupSelection bool - if opts.CleanOutputUsed { - cleanupSelection = *opts.CleanOutput + if opts.CleanOutputUsed || opts.KeepOutput { + cleanupSelection = opts.CleanOutput && !opts.KeepOutput } else { cleanupSelection = askCleanup() } diff --git a/internal/discovery.go b/internal/discovery.go index 3d76dd6..be2a9f8 100644 --- a/internal/discovery.go +++ b/internal/discovery.go @@ -21,8 +21,8 @@ func AutoDiscover(allFiles []string) ([]string, map[string]string) { func readFromSelections(allFiles []string, opts GIGenOptions) ([]string, map[string]string) { var answer bool - if opts.AutoDiscoverUsed && *opts.AutoDiscover { - answer = *opts.AutoDiscover + if opts.AutoDiscoverUsed && opts.AutoDiscover { + answer = opts.AutoDiscover } else { answer = askDiscovery() }