github.com/shivakar/gdupes@v0.0.0-20180726052558-d5c070c306d0/cmd/root.go (about) 1 // Copyright © 2017 Shivakar Vulli <svulli@shivakar.com> 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package cmd 22 23 import ( 24 "fmt" 25 "os" 26 "runtime" 27 28 "github.com/shivakar/gdupes/gdupes" 29 "github.com/spf13/cobra" 30 ) 31 32 var config gdupes.Config 33 34 // RootCmd represents the base command when called without any subcommands 35 var RootCmd = &cobra.Command{ 36 Use: "gdupes DIRECTORY...", 37 Short: "A multithreaded CLI tool for identifying duplicate files", 38 Long: `gdupes is a multithreaded command-line tool for identifying duplicate files.`, 39 RunE: func(cmd *cobra.Command, args []string) error { 40 _, err := gdupes.Run(&config, args) 41 return err 42 }, 43 } 44 45 // Execute adds all child commands to the root command sets flags appropriately. 46 // This is called by main.main(). It only needs to happen once to the rootCmd. 47 func Execute() { 48 if err := RootCmd.Execute(); err != nil { 49 fmt.Println(err) 50 os.Exit(-1) 51 } 52 } 53 54 func init() { 55 RootCmd.Flags().IntVarP(&config.NumWorkers, "concurrency", "c", 2*runtime.NumCPU(), "Number of concurrent threads to use") 56 RootCmd.Flags().BoolVarP(&config.Recurse, "recurse", "r", false, "Recurse through subdirectories") 57 // RootCmd.Flags().BoolVarP(&config.Symlinks, "symlinks", "s", false, "Follow symlinks") 58 RootCmd.Flags().BoolVarP(&config.Hardlinks, "hardlinks", "H", false, "Treat hardlinks as duplicates") 59 RootCmd.Flags().BoolVarP(&config.NoEmpty, "noempty", "n", false, "Exclude zero-length/empty files") 60 RootCmd.Flags().BoolVarP(&config.NoHidden, "nohidden", "A", false, "Exclude hidden files (POSIX only)") 61 RootCmd.Flags().BoolVarP(&config.Sameline, "sameline", "1", false, "List set of matches on the same line") 62 // RootCmd.Flags().BoolVarP(&config.Size, "size", "S", true, "Show size of duplicate files") 63 RootCmd.Flags().BoolVarP(&config.Summarize, "summarize", "m", false, "Summarize duplicates information") 64 // RootCmd.Flags().BoolVarP(&config.Quiet, "quiet", "q", false, "Hide progress indicator") 65 RootCmd.Flags().BoolVarP(&config.PrintVersion, "version", "v", false, "Display gdupes version") 66 RootCmd.Flags().BoolP("help", "h", false, "Display this help message") 67 }