From 7a21e4fd457f397a31bde68497bca817d9b36968 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 8 Jan 2020 22:00:00 +0800 Subject: [PATCH] refactor: update cmd config --- cmd/cloc.go | 205 ++++++++-------------------------------------------- 1 file changed, 31 insertions(+), 174 deletions(-) diff --git a/cmd/cloc.go b/cmd/cloc.go index 0b2042a..53f31e8 100644 --- a/cmd/cloc.go +++ b/cmd/cloc.go @@ -22,179 +22,36 @@ var clocCmd = &cobra.Command{ func init() { rootCmd.AddCommand(clocCmd) + addClocConfigs() +} + +func addClocConfigs() { flags := clocCmd.PersistentFlags() - flags.Int64Var( - &processor.AverageWage, - "avg-wage", - 56286, - "average wage value used for basic COCOMO calculation", - ) - flags.BoolVar( - &processor.DisableCheckBinary, - "binary", - false, - "disable binary file detection", - ) - flags.BoolVar( - &processor.Files, - "by-file", - false, - "display output for every file", - ) - flags.BoolVar( - &processor.Ci, - "ci", - false, - "enable CI output settings where stdout is ASCII", - ) - flags.BoolVar( - &processor.Ignore, - "no-ignore", - false, - "disables .ignore file logic", - ) - flags.BoolVar( - &processor.GitIgnore, - "no-gitignore", - false, - "disables .gitignore file logic", - ) - flags.BoolVar( - &processor.Debug, - "debug", - false, - "enable debug output", - ) - flags.StringSliceVar( - &processor.PathDenyList, - "exclude-dir", - []string{".git", ".hg", ".svn"}, - "directories to exclude", - ) - flags.IntVar( - &processor.GcFileCount, - "file-gc-count", - 10000, - "number of files to parse before turning the GC on", - ) - flags.StringVarP( - &processor.Format, - "format", - "f", - "tabular", - "set output format [tabular, wide, json, csv, cloc-yaml]", - ) - flags.StringSliceVarP( - &processor.AllowListExtensions, - "include-ext", - "i", - []string{}, - "limit to file extensions [comma separated list: e.g. go,java,js]", - ) - flags.BoolVarP( - &processor.Languages, - "languages", - "l", - false, - "print supported languages and extensions", - ) - flags.BoolVar( - &processor.Cocomo, - "no-cocomo", - false, - "remove COCOMO calculation output", - ) - flags.BoolVarP( - &processor.Complexity, - "no-complexity", - "c", - false, - "skip calculation of code complexity", - ) - flags.BoolVarP( - &processor.Duplicates, - "no-duplicates", - "d", - false, - "remove duplicate files from stats and output", - ) - flags.BoolVarP( - &processor.MinifiedGenerated, - "min-gen", - "z", - false, - "identify minified or generated files", - ) - flags.BoolVar( - &processor.IgnoreMinifiedGenerate, - "no-min-gen", - false, - "ignore minified or generated files in output (implies --min-gen)", - ) - flags.IntVar( - &processor.MinifiedGeneratedLineByteLength, - "min-gen-line-length", - 255, - "number of bytes per average line for file to be considered minified or generated", - ) - flags.StringArrayVarP( - &processor.Exclude, - "not-match", - "M", - []string{}, - "ignore files and directories matching regular expression", - ) - flags.StringVarP( - &processor.FileOutput, - "output", - "o", - "", - "output filename (default stdout)", - ) - flags.StringVarP( - &processor.SortBy, - "sort", - "s", - "files", - "column to sort by [files, name, lines, blanks, code, comments, complexity]", - ) - flags.BoolVarP( - &processor.Trace, - "trace", - "t", - false, - "enable trace output (not recommended when processing multiple files)", - ) - flags.BoolVarP( - &processor.Verbose, - "verbose", - "v", - false, - "verbose output", - ) - flags.BoolVarP( - &processor.More, - "wide", - "w", - false, - "wider output with additional statistics (implies --complexity)", - ) - flags.BoolVar( - &processor.NoLarge, - "no-large", - false, - "ignore files over certain byte and line size set by max-line-count and max-byte-count", - ) - flags.Int64Var( - &processor.LargeLineCount, - "large-line-count", - 40000, - "number of lines a file can contain before being removed from output", - ) - flags.Int64Var( - &processor.LargeByteCount, - "large-byte-count", - 1000000, - "number of bytes a file can contain before being removed from output", - ) + flags.Int64Var(&processor.AverageWage, "avg-wage", 56286, "average wage value used for basic COCOMO calculation", ) + flags.BoolVar(&processor.DisableCheckBinary, "binary", false, "disable binary file detection", ) + flags.BoolVar(&processor.Files, "by-file", false, "display output for every file", ) + flags.BoolVar(&processor.Ci, "ci", false, "enable CI output settings where stdout is ASCII", ) + flags.BoolVar(&processor.Ignore, "no-ignore", false, "disables .ignore file logic", ) + flags.BoolVar(&processor.GitIgnore, "no-gitignore", false, "disables .gitignore file logic", ) + flags.BoolVar(&processor.Debug, "debug", false, "enable debug output", ) + flags.StringSliceVar(&processor.PathDenyList, "exclude-dir", []string{".git", ".hg", ".svn"}, "directories to exclude", ) + flags.IntVar(&processor.GcFileCount, "file-gc-count", 10000, "number of files to parse before turning the GC on", ) + flags.StringVarP(&processor.Format, "format", "f", "tabular", "set output format [tabular, wide, json, csv, cloc-yaml]", ) + flags.StringSliceVarP(&processor.AllowListExtensions, "include-ext", "i", []string{}, "limit to file extensions [comma separated list: e.g. go,java,js]", ) + flags.BoolVarP(&processor.Languages, "languages", "l", false, "print supported languages and extensions", ) + flags.BoolVar(&processor.Cocomo, "no-cocomo", false, "remove COCOMO calculation output", ) + flags.BoolVarP(&processor.Complexity, "no-complexity", "c", false, "skip calculation of code complexity", ) + flags.BoolVarP(&processor.Duplicates, "no-duplicates", "d", false, "remove duplicate files from stats and output", ) + flags.BoolVarP(&processor.MinifiedGenerated, "min-gen", "z", false, "identify minified or generated files", ) + flags.BoolVar(&processor.IgnoreMinifiedGenerate, "no-min-gen", false, "ignore minified or generated files in output (implies --min-gen)", ) + flags.IntVar(&processor.MinifiedGeneratedLineByteLength, "min-gen-line-length", 255, "number of bytes per average line for file to be considered minified or generated", ) + flags.StringArrayVarP(&processor.Exclude, "not-match", "M", []string{}, "ignore files and directories matching regular expression", ) + flags.StringVarP(&processor.FileOutput, "output", "o", "", "output filename (default stdout)", ) + flags.StringVarP(&processor.SortBy, "sort", "s", "files", "column to sort by [files, name, lines, blanks, code, comments, complexity]", ) + flags.BoolVarP(&processor.Trace, "trace", "t", false, "enable trace output (not recommended when processing multiple files)", ) + flags.BoolVarP(&processor.Verbose, "verbose", "v", false, "verbose output", ) + flags.BoolVarP(&processor.More, "wide", "w", false, "wider output with additional statistics (implies --complexity)", ) + flags.BoolVar(&processor.NoLarge, "no-large", false, "ignore files over certain byte and line size set by max-line-count and max-byte-count", ) + flags.Int64Var(&processor.LargeLineCount, "large-line-count", 40000, "number of lines a file can contain before being removed from output", ) + flags.Int64Var(&processor.LargeByteCount, "large-byte-count", 1000000, "number of bytes a file can contain before being removed from output", ) } -- GitLab