Skip to content

Commit

Permalink
client: sets platform as flag in app create
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur authored and andrestc committed Jun 29, 2017
1 parent 2a0363b commit 182ddb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
9 changes: 6 additions & 3 deletions tsuru/client/apps.go
Expand Up @@ -32,6 +32,7 @@ type AppCreate struct {
router string
pool string
description string
platform string
tags cmd.StringSliceFlag
routerOpts cmd.MapFlag
fs *gnuflag.FlagSet
Expand Down Expand Up @@ -76,7 +77,7 @@ func newUnitSorter(m map[string]int) *unitSorter {
func (c *AppCreate) Info() *cmd.Info {
return &cmd.Info{
Name: "app-create",
Usage: "app-create <appname> <platform> [--plan/-p plan name] [--router/-r router name] [--team/-t team owner] [--pool/-o pool name] [--description/-d description] [--tag/-g tag]... [--router-opts key=value]...",
Usage: "app-create <appname> [--platform/-l platform] [--plan/-p plan name] [--router/-r router name] [--team/-t team owner] [--pool/-o pool name] [--description/-d description] [--tag/-g tag]... [--router-opts key=value]...",
Desc: `Creates a new app using the given name and platform. For tsuru,
a platform is provisioner dependent. To check the available platforms, use the
command [[tsuru platform-list]] and to add a platform use the command [[tsuru platform-add]].
Expand Down Expand Up @@ -132,6 +133,9 @@ func (c *AppCreate) Flags() *gnuflag.FlagSet {
routerMessage := "The router used by the app"
c.fs.StringVar(&c.router, "router", "", routerMessage)
c.fs.StringVar(&c.router, "r", "", routerMessage)
platformMessage := "The app's platform"
c.fs.StringVar(&c.platform, "platform", "", platformMessage)
c.fs.StringVar(&c.platform, "l", "", platformMessage)
teamMessage := "Team owner app"
c.fs.StringVar(&c.teamOwner, "team", "", teamMessage)
c.fs.StringVar(&c.teamOwner, "t", "", teamMessage)
Expand All @@ -151,13 +155,12 @@ func (c *AppCreate) Flags() *gnuflag.FlagSet {

func (c *AppCreate) Run(context *cmd.Context, client *cmd.Client) error {
appName := context.Args[0]
platform := context.Args[1]
v, err := form.EncodeToValues(map[string]interface{}{"routeropts": c.routerOpts})
if err != nil {
return err
}
v.Set("name", appName)
v.Set("platform", platform)
v.Set("platform", c.platform)
v.Set("plan", c.plan)
v.Set("teamOwner", c.teamOwner)
v.Set("pool", c.pool)
Expand Down
29 changes: 16 additions & 13 deletions tsuru/client/apps_test.go
Expand Up @@ -39,7 +39,7 @@ func (s *S) TestAppCreate(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -63,6 +63,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -75,7 +76,7 @@ func (s *S) TestAppCreateTeamOwner(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -99,7 +100,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"-t", "team"})
command.Flags().Parse(true, []string{"-t", "team", "--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -112,7 +113,7 @@ func (s *S) TestAppCreatePlan(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -137,6 +138,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"-p", "myplan"})
command.Flags().Parse(true, []string{"--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -149,7 +151,7 @@ func (s *S) TestAppCreatePool(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -173,7 +175,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"-o", "mypool"})
command.Flags().Parse(true, []string{"-o", "mypool", "--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -186,7 +188,7 @@ func (s *S) TestAppCreateRouterOpts(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -212,7 +214,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"--router-opts", "a=1", "--router-opts", "b=2"})
command.Flags().Parse(true, []string{"--router-opts", "a=1", "--router-opts", "b=2", "--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -224,7 +226,7 @@ func (s *S) TestAppCreateNoRepository(c *check.C) {
expected := `App "ble" has been created!
Use app-info to check the status of the app and its units.` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -248,6 +250,7 @@ Use app-info to check the status of the app and its units.` + "\n"
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -274,7 +277,7 @@ func (s *S) TestAppCreateWithTags(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -298,7 +301,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"--tag", "tag1", "--tag", "tag2"})
command.Flags().Parse(true, []string{"--tag", "tag1", "--tag", "tag2", "--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand All @@ -311,7 +314,7 @@ func (s *S) TestAppCreateWithEmptyTag(c *check.C) {
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble", "django"},
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
Expand All @@ -335,7 +338,7 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
command.Flags().Parse(true, []string{"--tag", ""})
command.Flags().Parse(true, []string{"--tag", "", "--platform", "django"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
Expand Down

0 comments on commit 182ddb2

Please sign in to comment.