-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (87 loc) · 2.01 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
99
100
package main
import (
"context"
"fmt"
"os"
"github.com/cristalhq/acmd"
)
type CommandReceiver interface {
runDockerCommand(args ...string)
}
type Command interface {
execute(r *CommandReceiver)
}
type Invoker struct {
command Command
}
type BaseCommand struct {
Receiver string
}
func (c BaseCommand) Process() {}
func ServiceCommandGroup() bool {
args := os.Args[1:]
if len(args) < 3 {
return false
}
service := args[1]
command := args[2]
fmt.Printf("Service: %s, Command: %s\n", service, command)
return true
}
func main() {
cmds := []acmd.Command{
{
Name: "ps",
Description: "docker ps with better formatting",
ExecFunc: func(ctx context.Context, args []string) error {
RunDockerCommand("ps", "--format", "table {{.Names}}\t{{.Image}}\t{{.Status}}")
return nil
},
},
{
Name: "ptag",
Description: "docker ps with better formatting",
ExecFunc: func(ctx context.Context, args []string) error {
RunDockerCommand("tag", args[0])
RunDockerCommand("push", args[1])
return nil
},
},
}
r := acmd.RunnerOf(cmds, acmd.Config{})
if err := r.Run(); err != nil {
RunDockerCommand(os.Args[1:]...)
//r.Exit(err)
}
fmt.Println("Bar")
}
// github.com/cristalhq/acmd parser := argparse.NewParser("docker-cli", "Wraps the Docker command")
// var firstArgument = parser.StringPositional(&argparse.Options{Required: true})
// err := parser.Parse(os.Args)
// if err != nil {
// fmt.Print(parser.Usage(err))
// RunDockerCommand(os.Args[1:]...)
// } else {
// fmt.Println("something" + *firstArgument)
// }
// // args := os.Args[1:]
// // // load up the commands here
// // switch {
// // case len(args) == 0:
// //
// // fmt.Println("No command provided")
// // os.Exit(1)
// //
// // case args[0] == "service" && ServiceCommandGroup():
// //
// // // Do nothing, as the service command is already handled in ServiceCommandGroup
// //
// // case args[0] == "ps":
// //
// // CmdPs(args...)
// //
// // default:
// //
// // RunDockerCommand(args...)
// // }
//}