This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathcommit.go
57 lines (51 loc) · 1.65 KB
/
commit.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
package client
import (
"fmt"
"os"
"strings"
gflag "github.com/jessevdk/go-flags"
)
/*
-a, --author= Author (e.g., "Hello World <hello@a-team.com>")
-c, --change=[] Apply Dockerfile instruction to the created image
-m, --message= Commit message
-p, --pause Pause container during Commit
-h, --help Print usage
*/
func (cli *HyperClient) HyperCmdCommit(args ...string) error {
var opts struct {
Author string `short:"a" long:"author" default:"" value-name:"\"\"" description:"Author (e.g., \"Hello World <hello@a-team.com>\")"`
Change []string `short:"c" long:"change" default:"" value-name:"[]" description:"Apply Dockerfile instruction to the created image"`
Message string `short:"m" long:"message" default:"" value-name:"\"\"" description:"Commit message"`
Pause bool `short:"p" long:"pause" description:"Pause container during Commit"`
}
var parser = gflag.NewParser(&opts, gflag.Default)
parser.Usage = "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]\n\nCreate a new image from a container's changes"
args, err := parser.ParseArgs(args)
if err != nil {
if !strings.Contains(err.Error(), "Usage") {
return err
} else {
return nil
}
}
if len(args) == 0 {
return fmt.Errorf("%s: \"commit\" requires a minimum of 1 argument, See 'hyperctl build --help'.", os.Args[0])
}
var (
containerId string = ""
repo string = ""
)
if len(args) > 0 {
containerId = args[0]
}
if len(args) > 1 {
repo = args[1]
}
id, err := cli.client.Commit(containerId, repo, opts.Author, opts.Message, opts.Change, opts.Pause)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s\n", id)
return nil
}