func main() { var args []string flag.Parse() flagSetup() // note - this must stay in main() so profile data is flushed at close if flagCpuProfile != "" { f, err := os.Create(flagCpuProfile) if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) return } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } if flagStdin { args = mdr.GetAllArgs() } else { args = flag.Args() if len(args) == 0 { args = append(args, `.`) } } if flagMd { fmt.Printf("```\n") fmt.Printf("SLOC output\n\n") } for _, filePathName := range args { add(filePathName) } if Verbose { for i := 0; i < len(files); i++ { fmt.Printf("File [%3d] %s\n", i+1, files[i]) } } if flagNoOp { fmt.Printf("files[] has %d entries\n", len(files)) fmt.Println("-n flag given - exiting") os.Exit(0) } for _, f := range files { handleFile(f) } if flagUseJson { printJSON() } else { printInfo() } if flagMd { fmt.Printf("```\n") } }
func main() { argList := mdr.GetAllArgs() fp, err := os.Create("output.lst") if err != nil { fmt.Printf("Cant create output.lst\n") os.Exit(-1) } defer fp.Close() for _, s := range argList { s = fmt.Sprintf("%s\n", s) nw, err := fp.WriteString(s) if (err != nil) || (nw <= 0) { // never 0 on success fmt.Printf("Cant write output.lst\n") break } } fmt.Printf("Args gathered = %v\n", argList) }