-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
132 lines (120 loc) · 2.94 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"errors"
"fmt"
"os"
"strings"
"github.com/tokibi/undocker"
"github.com/urfave/cli"
)
var version = "unknown"
func main() {
u := undocker.Undocker{
Out: os.Stdout,
Err: os.Stderr,
}
opts := undocker.Options{}
app := cli.NewApp()
app.Name = "undocker"
app.Usage = "Decompose docker images."
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "registry-url, r",
Usage: "docker registry url",
EnvVar: "REGISTRY_URL",
Destination: &opts.RegistryURL,
},
cli.StringFlag{
Name: "registry-user, u",
Usage: "docker registry login username",
EnvVar: "REGISTRY_USER",
Destination: &opts.RegistryUser,
},
cli.StringFlag{
Name: "registry-pass, p",
Usage: "docker registry login password",
EnvVar: "REGISTRY_PASS",
Destination: &opts.RegistryPass,
},
cli.StringFlag{
Name: "tmpdir",
Value: "/tmp/undocker",
Usage: "temporal directory to extract image",
EnvVar: "UNDOCKER_TMP_PATH",
Destination: &opts.TmpPath,
},
}
extractCommand := cli.Command{
Name: "extract",
Aliases: []string{"e"},
Usage: "Extract to rootfs.",
ArgsUsage: "[image] [destination]",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "overwrite-symlink-refs, s",
Usage: "Overwrite symbolic link references",
Destination: &opts.Extract.OverwriteSymlinkRefs,
},
},
Action: func(c *cli.Context) error {
repo, tag, err := parseReference(c.Args().Get(0))
if err != nil {
return cli.ShowCommandHelp(c, "extract")
}
dest := c.Args().Get(1)
if dest == "" {
dest = "."
}
return u.Extract(repo, tag, dest, opts)
},
}
showCommand := cli.Command{
Name: "show",
Aliases: []string{"s"},
Usage: "Show image informations",
Subcommands: []cli.Command{
{
Name: "config",
Usage: "Show image configuration",
ArgsUsage: "[image]",
Action: func(c *cli.Context) error {
repo, tag, err := parseReference(c.Args().Get(0))
if err != nil {
return cli.ShowCommandHelp(c, "config")
}
return u.Config(repo, tag, opts)
},
},
// {
// Name: "manifest",
// Usage: "Show image manifest",
// ArgsUsage: "[image]",
// Action: func(c *cli.Context) error {
// repo, tag, err := parseReference(c.Args().Get(0))
// if err != nil {
// return cli.ShowCommandHelp(c, "config")
// }
// return u.Config(repo, tag, opts)
// },
// },
},
}
app.Commands = append(app.Commands, extractCommand)
app.Commands = append(app.Commands, showCommand)
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(3)
}
}
func parseReference(arg string) (repository, tag string, err error) {
ref := strings.SplitN(arg, ":", 2)
if ref[0] == "" {
return "", "", errors.New("Invalid image")
}
if len(ref) < 2 {
return ref[0], "latest", nil
}
return ref[0], ref[1], nil
}