grim/convey

Bump the version for release
v0.14.0-alpha3
2018-02-20, Gary Kramlich
166a6d1979fa
Bump the version for release
// Convey
// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package docker
import (
"fmt"
"strings"
"github.com/alecthomas/kingpin"
"bitbucket.org/rw_grim/convey/tasks"
)
// ParseCommand is a super stripped down kingpin parser that will parse docker
// command line options and return a convey task or an error
func ParseCommand(argv []string) (tasks.Task, error) {
app := kingpin.New("", "")
login := app.Command("login", "")
loginUsername := login.Flag("username", "").Short('u').Default("").String()
loginPassword := login.Flag("password", "").Short('p').Default("").String()
// `aws ecr get-login adds environment variables to the login command,
// this handles that, but we ignore them.
login.Flag("env", "").Short('e').Default("").Strings()
loginServer := login.Arg("", "").String()
logout := app.Command("logout", "")
logoutServer := logout.Arg("", "").String()
build := app.Command("build", "")
buildTag := build.Flag("tag", "").Short('t').String()
buildContext := build.Arg("", "").String()
push := app.Command("push", "")
pushImage := push.Arg("", "").Required().String()
pull := app.Command("pull", "")
pullImage := pull.Arg("", "").Required().String()
rmi := app.Command("rmi", "")
rmi.Flag("--force", "").Short('f').Default("false").Bool()
rmiImage := rmi.Arg("", "").Required().String()
run := app.Command("run", "")
runEntryPoint := run.Flag("entrypoint", "").String()
runEnv := run.Flag("env", "").Short('e').Strings()
runImage := run.Arg("image", "").Required().String()
runWorkdir := run.Flag("workdir", "").Short('w').String()
runCommand := run.Arg("", "").Strings()
tag := app.Command("tag", "")
tagSource := tag.Arg("src", "").Required().String()
tagDestination := tag.Arg("dest", "").Required().String()
cmd, err := app.Parse(argv[1:])
if err != nil {
return nil, err
}
var task tasks.Task
switch cmd {
case "build":
task = &Build{
Tag: *buildTag,
Files: []string{*buildContext},
}
case "login":
task = &Login{
Username: *loginUsername,
Password: *loginPassword,
Server: *loginServer,
}
case "logout":
task = &Logout{
Server: *logoutServer,
}
case "pull":
task = &Pull{
Image: *pullImage,
}
case "push":
task = &Push{
Image: *pushImage,
}
case "rmi":
task = &Remove{
Image: *rmiImage,
}
case "run":
task = &Run{
Command: strings.Join(*runCommand, " "),
Image: *runImage,
EntryPoint: *runEntryPoint,
Environment: *runEnv,
WorkDir: *runWorkdir,
}
case "tag":
task = &Tag{
Source: *tagSource,
Destination: *tagDestination,
}
}
if task != nil {
return task, nil
}
return nil, fmt.Errorf("unable to parse docker command line '%v'", argv)
}