-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (48 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/spf13/cobra"
kommand "github.com/braswelljr/rmx/command"
"github.com/braswelljr/rmx/rm"
)
var (
Rmx = rm.Rm{
Stdin: os.Stdin,
Stdout: os.Stdout,
}
)
func main() {
// get root command
command := &cobra.Command{
Use: "rmx " + color.MagentaString("[flags]...") + " " + color.YellowString("[directory / file]..."),
Short: "A cross-platform replacement for UNIX " + color.YellowString("rm") + " command.",
Long: "A cross-platform replacement for UNIX " + color.YellowString("rm") + " command.",
Args: kommand.ArgumentValidator(&Rmx),
RunE: func(command *cobra.Command, args []string) error {
Rmx.Directory = "."
if len(args) > 0 {
Rmx.Directory = args[0]
// run command and return any error
return kommand.Run(&Rmx, command, args)
}
return nil
},
}
// add flags
command.PersistentFlags().BoolP("help", "h", false, "help for this command")
command.Flags().BoolVarP(&Rmx.Flags.F, "force", "f", false, "ignore nonexistent files and arguments, never prompt")
command.Flags().BoolVarP(&Rmx.Flags.Ii, "interactive", "i", false, "prompt before every removal")
command.Flags().BoolVarP(&Rmx.Flags.II, "INTERACTIVE", "I", false, "prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes")
command.Flags().BoolVarP(&Rmx.Flags.Rr, "recursive", "r", false, "remove directories and their contents recursively")
command.Flags().BoolVarP(&Rmx.Flags.RR, "RECURSIVE", "R", false, "remove directories and their contents recursively")
command.Flags().BoolVarP(&Rmx.Flags.D, "dir", "d", false, "remove empty directories")
command.PersistentFlags().BoolVarP(&Rmx.Flags.V, "verbose", "v", false, "explain what is being done")
command.Flags().Float32Var(&Rmx.Flags.Version, "version", 0.01, "output version information and exit")
// clean up and exit on error
if err := command.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err) // print error to stderr
os.Exit(1) // exit on error
}
}