Skip to content

Commit 206d44c

Browse files
authored
Merge pull request #4 from dogpatch626/feat/cobra
Feat/cobra
2 parents f42f71e + 1edd8f7 commit 206d44c

File tree

12 files changed

+201
-101
lines changed

12 files changed

+201
-101
lines changed

.env

Whitespace-only changes.

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11

2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out
14+
15+
# Dependency directories (remove the comment below to include it)
16+
# vendor/
17+
18+
# Go workspace file
19+
go.work
20+
go.work.sum
21+
22+
# env file
23+
.env

CodexCli

-2.93 MB
Binary file not shown.

banner/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import (
66

77
func Banner() {
88

9-
banner := figure.NewColorFigure("Codex", "isometric1", "red", true)
9+
banner := figure.NewColorFigure("Codex", "banner3-D", "white", true)
1010
banner.Print()
1111
}

commands/Info.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Commands
2+
3+
import (
4+
"github.com/fatih/color"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var infoCmd = &cobra.Command{
9+
Use: "info",
10+
Aliases: []string{"info"},
11+
Short: "CodexCli is a in development cli",
12+
Run: func(cmd *cobra.Command, args []string) {
13+
color.Red("CodexCli is a in-development cli made in go as a project to learn what is even going on with this lang.")
14+
},
15+
}
16+
17+
func init() {
18+
19+
rootCmd.AddCommand(infoCmd)
20+
21+
}

commands/Root.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package Commands
2+
3+
import (
4+
"CodexCli/banner"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var rootCmd = &cobra.Command{
13+
Use: "Codex",
14+
Short: "Codex is a virus total cli",
15+
Long: "Codex is a virus total cli built by dogpatch626 in Go",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
banner.Banner()
18+
ran := exec.Command("./CodexCli", "--help")
19+
20+
out, err := ran.Output()
21+
22+
if err != nil {
23+
fmt.Println("Could not run: --help", err)
24+
}
25+
26+
fmt.Println("\n", string(out))
27+
28+
},
29+
}
30+
31+
func Execute() {
32+
if err := rootCmd.Execute(); err != nil {
33+
fmt.Println(err)
34+
os.Exit(1)
35+
}
36+
}

commands/commands.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

commands/scan.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package Commands
2+
3+
import (
4+
"encoding/base64"
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
"net/url"
9+
"os"
10+
11+
vt "github.com/VirusTotal/vt-go"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var vtkey string
16+
var scanCmd = &cobra.Command{
17+
Use: "scan",
18+
Short: "Scan a url using the Virus total api",
19+
20+
Run: func(cmd *cobra.Command, args []string) {
21+
22+
if vtkey == "" {
23+
fmt.Println("Must pass --vtkey argument.")
24+
os.Exit(0)
25+
}
26+
27+
var urlID = base64.RawURLEncoding.EncodeToString([]byte(args[0]))
28+
29+
client := vt.NewClient(vtkey)
30+
31+
analyseslink := "https://www.virustotal.com/api/v3/urls/" + urlID
32+
33+
analysisurl, parseurlerr := url.Parse(analyseslink)
34+
fmt.Println(analyseslink)
35+
if parseurlerr != nil {
36+
log.Fatal(parseurlerr)
37+
}
38+
39+
getId, idErr := client.Get(analysisurl)
40+
41+
if idErr != nil {
42+
log.Fatal(idErr)
43+
}
44+
var dat map[string]interface{}
45+
46+
decodeerr := json.Unmarshal(getId.Data, &dat)
47+
if decodeerr != nil {
48+
log.Panic(decodeerr)
49+
}
50+
// Iterate through data
51+
for key, value := range dat {
52+
fmt.Printf("Key: %s\n", key)
53+
54+
switch v := value.(type) {
55+
case string:
56+
fmt.Printf("Value: %s\n", v)
57+
case float64:
58+
fmt.Printf("Value: %f\n", v)
59+
case map[string]interface{}:
60+
// Recursively handle nested maps
61+
for nestedKey, nestedValue := range v {
62+
63+
switch nv := nestedValue.(type) {
64+
65+
case map[string]interface{}:
66+
67+
for nestedKey, nestedValue := range nv {
68+
switch fn := nestedValue.(type) {
69+
70+
case map[string]interface{}:
71+
for fkey, nvalue := range fn {
72+
fmt.Printf(" ----: %s", fkey)
73+
fmt.Printf("%v\n", nvalue)
74+
}
75+
}
76+
77+
fmt.Printf(" --------: %s", nestedKey)
78+
fmt.Printf(": %v\n", nestedValue)
79+
80+
}
81+
fmt.Printf(" --: %s", nestedKey)
82+
fmt.Printf(": %v\n", nestedValue)
83+
}
84+
}
85+
default:
86+
fmt.Printf("Unknown type: %T\n", v)
87+
}
88+
}
89+
},
90+
}
91+
92+
func init() {
93+
scanCmd.Flags().StringVarP(&vtkey, "vtkey", "v", "", "Virus Total key for api calls")
94+
rootCmd.AddCommand(scanCmd)
95+
}

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ module CodexCli
33
go 1.23.1
44

55
require (
6+
github.com/VirusTotal/vt-go v1.0.1 // indirect
67
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
78
github.com/fatih/color v1.17.0 // indirect
8-
github.com/joho/godotenv v1.5.1 // indirect
9+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
910
github.com/mattn/go-colorable v0.1.13 // indirect
1011
github.com/mattn/go-isatty v0.0.20 // indirect
12+
github.com/spf13/cobra v1.8.1 // indirect
13+
github.com/spf13/pflag v1.0.5 // indirect
14+
github.com/thedevsaddam/gojsonq/v2 v2.5.2 // indirect
1115
golang.org/x/sys v0.18.0 // indirect
1216
)

go.sum

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
github.com/VirusTotal/vt-go v1.0.1 h1:rj/qugIY8XNC6ogwOaeJAGCOsb3nmY63+yuDMtHOx0Q=
2+
github.com/VirusTotal/vt-go v1.0.1/go.mod h1:u1+HeRyl/gQs67eDgVEWNE7+x+zCyXhdtNVrRJR5YPE=
13
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
24
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
5+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
6+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
37
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
48
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
5-
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6-
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
9+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
10+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
711
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
812
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
913
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
1014
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1115
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
16+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
18+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
19+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
20+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
21+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
22+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
23+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
24+
github.com/thedevsaddam/gojsonq/v2 v2.5.2 h1:CoMVaYyKFsVj6TjU6APqAhAvC07hTI6IQen8PHzHYY0=
25+
github.com/thedevsaddam/gojsonq/v2 v2.5.2/go.mod h1:bv6Xa7kWy82uT0LnXPE2SzGqTj33TAEeR560MdJkiXs=
1226
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1327
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1428
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
1529
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
30+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
32+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)