PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/main.go

https://github.com/boyter/scc
Go | 254 lines | 241 code | 7 blank | 6 comment | 4 complexity | 939b6a2e7925d357195117eeb35ca369 MD5 | raw file
  1// SPDX-License-Identifier: MIT
  2// SPDX-License-Identifier: Unlicense
  3
  4package main
  5
  6import (
  7	"fmt"
  8	"github.com/boyter/scc/processor"
  9	"github.com/spf13/cobra"
 10	"os"
 11)
 12
 13//go:generate go run scripts/include.go
 14func main() {
 15	//f, _ := os.Create("scc.pprof")
 16	//pprof.StartCPUProfile(f)
 17	//defer pprof.StopCPUProfile()
 18
 19	rootCmd := &cobra.Command{
 20		Use:     "scc",
 21		Short:   "scc [FILE or DIRECTORY]",
 22		Long:    fmt.Sprintf("Sloc, Cloc and Code. Count lines of code in a directory with complexity estimation.\nVersion %s\nBen Boyter <ben@boyter.org> + Contributors", processor.Version),
 23		Version: processor.Version,
 24		Run: func(cmd *cobra.Command, args []string) {
 25			processor.DirFilePaths = args
 26			if processor.ConfigureLimits != nil {
 27				processor.ConfigureLimits()
 28			}
 29			processor.ConfigureGc()
 30			processor.ConfigureLazy(true)
 31			processor.Process()
 32		},
 33	}
 34
 35	flags := rootCmd.PersistentFlags()
 36
 37	flags.Int64Var(
 38		&processor.AverageWage,
 39		"avg-wage",
 40		56286,
 41		"average wage value used for basic COCOMO calculation",
 42	)
 43	flags.BoolVar(
 44		&processor.DisableCheckBinary,
 45		"binary",
 46		false,
 47		"disable binary file detection",
 48	)
 49	flags.BoolVar(
 50		&processor.Files,
 51		"by-file",
 52		false,
 53		"display output for every file",
 54	)
 55	flags.BoolVar(
 56		&processor.Ci,
 57		"ci",
 58		false,
 59		"enable CI output settings where stdout is ASCII",
 60	)
 61	flags.BoolVar(
 62		&processor.Ignore,
 63		"no-ignore",
 64		false,
 65		"disables .ignore file logic",
 66	)
 67	flags.BoolVar(
 68		&processor.GitIgnore,
 69		"no-gitignore",
 70		false,
 71		"disables .gitignore file logic",
 72	)
 73	flags.BoolVar(
 74		&processor.Debug,
 75		"debug",
 76		false,
 77		"enable debug output",
 78	)
 79	flags.StringSliceVar(
 80		&processor.PathDenyList,
 81		"exclude-dir",
 82		[]string{".git", ".hg", ".svn"},
 83		"directories to exclude",
 84	)
 85	flags.IntVar(
 86		&processor.GcFileCount,
 87		"file-gc-count",
 88		10000,
 89		"number of files to parse before turning the GC on",
 90	)
 91	flags.StringVarP(
 92		&processor.Format,
 93		"format",
 94		"f",
 95		"tabular",
 96		"set output format [tabular, wide, json, csv, cloc-yaml, html, html-table]",
 97	)
 98	flags.StringSliceVarP(
 99		&processor.AllowListExtensions,
100		"include-ext",
101		"i",
102		[]string{},
103		"limit to file extensions [comma separated list: e.g. go,java,js]",
104	)
105	flags.BoolVarP(
106		&processor.Languages,
107		"languages",
108		"l",
109		false,
110		"print supported languages and extensions",
111	)
112	flags.BoolVar(
113		&processor.Cocomo,
114		"no-cocomo",
115		false,
116		"remove COCOMO calculation output",
117	)
118	flags.BoolVarP(
119		&processor.Complexity,
120		"no-complexity",
121		"c",
122		false,
123		"skip calculation of code complexity",
124	)
125	flags.BoolVarP(
126		&processor.Duplicates,
127		"no-duplicates",
128		"d",
129		false,
130		"remove duplicate files from stats and output",
131	)
132	flags.BoolVarP(
133		&processor.MinifiedGenerated,
134		"min-gen",
135		"z",
136		false,
137		"identify minified or generated files",
138	)
139	flags.BoolVarP(
140		&processor.Minified,
141		"min",
142		"",
143		false,
144		"identify minified files",
145	)
146	flags.BoolVarP(
147		&processor.Generated,
148		"gen",
149		"",
150		false,
151		"identify generated files",
152	)
153	flags.StringSliceVarP(
154		&processor.GeneratedMarkers,
155		"generated-markers",
156		"",
157		[]string{"do not edit"},
158		"string markers in head of generated files",
159	)
160	flags.BoolVar(
161		&processor.IgnoreMinifiedGenerate,
162		"no-min-gen",
163		false,
164		"ignore minified or generated files in output (implies --min-gen)",
165	)
166	flags.BoolVar(
167		&processor.IgnoreMinified,
168		"no-min",
169		false,
170		"ignore minified files in output (implies --min)",
171	)
172	flags.BoolVar(
173		&processor.IgnoreGenerated,
174		"no-gen",
175		false,
176		"ignore generated files in output (implies --gen)",
177	)
178	flags.IntVar(
179		&processor.MinifiedGeneratedLineByteLength,
180		"min-gen-line-length",
181		255,
182		"number of bytes per average line for file to be considered minified or generated",
183	)
184	flags.StringArrayVarP(
185		&processor.Exclude,
186		"not-match",
187		"M",
188		[]string{},
189		"ignore files and directories matching regular expression",
190	)
191	flags.StringVarP(
192		&processor.FileOutput,
193		"output",
194		"o",
195		"",
196		"output filename (default stdout)",
197	)
198	flags.StringVarP(
199		&processor.SortBy,
200		"sort",
201		"s",
202		"files",
203		"column to sort by [files, name, lines, blanks, code, comments, complexity]",
204	)
205	flags.BoolVarP(
206		&processor.Trace,
207		"trace",
208		"t",
209		false,
210		"enable trace output (not recommended when processing multiple files)",
211	)
212	flags.BoolVarP(
213		&processor.Verbose,
214		"verbose",
215		"v",
216		false,
217		"verbose output",
218	)
219	flags.BoolVarP(
220		&processor.More,
221		"wide",
222		"w",
223		false,
224		"wider output with additional statistics (implies --complexity)",
225	)
226	flags.BoolVar(
227		&processor.NoLarge,
228		"no-large",
229		false,
230		"ignore files over certain byte and line size set by max-line-count and max-byte-count",
231	)
232	flags.Int64Var(
233		&processor.LargeLineCount,
234		"large-line-count",
235		40000,
236		"number of lines a file can contain before being removed from output",
237	)
238	flags.Int64Var(
239		&processor.LargeByteCount,
240		"large-byte-count",
241		1000000,
242		"number of bytes a file can contain before being removed from output",
243	)
244	flags.StringVar(
245		&processor.CountAs,
246		"count-as",
247		"",
248		"count extension as language [e.g. jsp:htm,chead:\"C Header\" maps extension jsp to html and chead to C Header]",
249	)
250
251	if err := rootCmd.Execute(); err != nil {
252		os.Exit(1)
253	}
254}