Merge pull request #214 from HuKeping/constant

Replace exit codes by Constants
This commit is contained in:
Kenfe-Mickaël Laventure 2016-04-26 16:46:23 -07:00
commit 25de9de446
3 changed files with 20 additions and 10 deletions

View file

@ -43,7 +43,7 @@ func listCheckpoints(context *cli.Context) {
id = context.Args().First()
)
if id == "" {
fatal("container id cannot be empty", 1)
fatal("container id cannot be empty", ExitStatusMissingArg)
}
resp, err := c.ListCheckpoint(netcontext.Background(), &types.ListCheckpointRequest{
Id: id,
@ -88,10 +88,10 @@ var createCheckpointCommand = cli.Command{
name = context.Args().Get(1)
)
if containerID == "" {
fatal("container id at cannot be empty", 1)
fatal("container id at cannot be empty", ExitStatusMissingArg)
}
if name == "" {
fatal("checkpoint name cannot be empty", 1)
fatal("checkpoint name cannot be empty", ExitStatusMissingArg)
}
c := getClient(context)
if _, err := c.CreateCheckpoint(netcontext.Background(), &types.CreateCheckpointRequest{
@ -118,10 +118,10 @@ var deleteCheckpointCommand = cli.Command{
name = context.Args().Get(1)
)
if containerID == "" {
fatal("container id at cannot be empty", 1)
fatal("container id at cannot be empty", ExitStatusMissingArg)
}
if name == "" {
fatal("checkpoint name cannot be empty", 1)
fatal("checkpoint name cannot be empty", ExitStatusMissingArg)
}
c := getClient(context)
if _, err := c.DeleteCheckpoint(netcontext.Background(), &types.DeleteCheckpointRequest{

10
ctr/const.go Normal file
View file

@ -0,0 +1,10 @@
package main
// ctr wide constants
const (
// ExitStatusOK indicates successful completion
ExitStatusOK = 0
// ExitStatusMissingArg indicates failure due to missing argument(s)
ExitStatusMissingArg = 1
)

View file

@ -153,10 +153,10 @@ var startCommand = cli.Command{
path = context.Args().Get(1)
)
if path == "" {
fatal("bundle path cannot be empty", 1)
fatal("bundle path cannot be empty", ExitStatusMissingArg)
}
if id == "" {
fatal("container id cannot be empty", 1)
fatal("container id cannot be empty", ExitStatusMissingArg)
}
bpath, err := filepath.Abs(path)
if err != nil {
@ -343,7 +343,7 @@ var pauseCommand = cli.Command{
Action: func(context *cli.Context) {
id := context.Args().First()
if id == "" {
fatal("container id cannot be empty", 1)
fatal("container id cannot be empty", ExitStatusMissingArg)
}
c := getClient(context)
_, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{
@ -363,7 +363,7 @@ var resumeCommand = cli.Command{
Action: func(context *cli.Context) {
id := context.Args().First()
if id == "" {
fatal("container id cannot be empty", 1)
fatal("container id cannot be empty", ExitStatusMissingArg)
}
c := getClient(context)
_, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{
@ -395,7 +395,7 @@ var killCommand = cli.Command{
Action: func(context *cli.Context) {
id := context.Args().First()
if id == "" {
fatal("container id cannot be empty", 1)
fatal("container id cannot be empty", ExitStatusMissingArg)
}
c := getClient(context)
if _, err := c.Signal(netcontext.Background(), &types.SignalRequest{