grim/convey

Bump the version for release
v0.11.1
2017-10-21, Gary Kramlich
00923ff4e245
Bump the version for release
/*
* Convey
* Copyright 2016-2017 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 bitbucket
import (
"fmt"
"strings"
"github.com/alecthomas/kingpin"
"bitbucket.org/rw_grim/convey/docker"
"bitbucket.org/rw_grim/convey/tasks"
)
// parseDockerCommand is a super stripped down kingpin parse that will parse
// docker command line options and return a convey task or an error
func parseDockerCommand(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()
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 = &docker.Build{
Tag: *buildTag,
Files: []string{*buildContext},
}
case "login":
task = &docker.Login{
Username: *loginUsername,
Password: *loginPassword,
Server: *loginServer,
}
case "logout":
task = &docker.Logout{
Server: *logoutServer,
}
case "pull":
task = &docker.Pull{
Image: *pullImage,
}
case "push":
task = &docker.Push{
Image: *pushImage,
}
case "rmi":
task = &docker.Remove{
Image: *rmiImage,
}
case "run":
task = &docker.Run{
Command: strings.Join(*runCommand, " "),
Image: *runImage,
EntryPoint: *runEntryPoint,
Environment: *runEnv,
WorkDir: *runWorkdir,
}
case "tag":
task = &docker.Tag{
Source: *tagSource,
Destination: *tagDestination,
}
}
if task != nil {
return task, nil
}
return nil, fmt.Errorf("unable to parse docker command line '%v'", argv)
}