-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (90 loc) · 2.8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"log"
"main/core"
"os"
)
var version = "1.0.0"
var (
enableAlgorithms cli.StringSlice
threads int
)
func main() {
app := &cli.App{
EnableBashCompletion: true,
Name: "hash",
Usage: "calculate the core value of a file or string",
Version: "v" + version,
CustomAppHelpTemplate: fmt.Sprintf("%s\n%s\n", getBanner(), cli.AppHelpTemplate),
Action: func(context *cli.Context) error {
if len(os.Args) == 1 {
err := cli.ShowAppHelp(context)
if err != nil {
return err
}
}
return nil
},
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "enable",
Aliases: []string{"e"},
Value: cli.NewStringSlice("crc32", "md5", "sha1", "sha256", "sha512"),
Usage: "enabled hashing algorithms",
Destination: &enableAlgorithms,
},
&cli.StringSliceFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "file path",
Action: func(context *cli.Context, strings []string) error {
core.FilesHashReport(strings, enableAlgorithms.Value(), threads)
return nil
},
},
&cli.IntFlag{
Name: "thread",
Value: 6,
Aliases: []string{"t"},
Usage: "number of threads",
Destination: &threads,
},
&cli.StringFlag{
Name: "string",
Aliases: []string{"s"},
Usage: "computes a string core",
Action: func(context *cli.Context, s string) error {
core.StringHashReport(s, enableAlgorithms.Value())
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func getBanner() string {
yellow := color.New(color.FgYellow).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
cyan := color.New(color.FgCyan).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
return `
██ ██ ██
░██ ░██ ░██
░██ ░██ ██████ ██████░██
░██████████ ░░░░░░██ ██░░░░ ░██████
░██░░░░░░██ ███████ ░░█████ ░██░░░██
░██ ░██ ██░░░░██ ░░░░░██░██ ░██
░██ ░██░░████████ ██████ ░██ ░██
░░ ░░ ░░░░░░░░ ░░░░░░ ░░ ░░` +
"\n" +
green("v"+version) +
"\n" +
red("Powered by ") + cyan("G3G4X5X6") +
"\n" +
yellow("——————————————————————————————————————————————————————————")
}