add keep-output flag

This commit is contained in:
Chen Asraf
2022-05-25 23:01:18 +03:00
parent 8a3aceba7d
commit 7539222b7c
4 changed files with 23 additions and 12 deletions

View File

@@ -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.<br />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. |

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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()
}