| ... | ... |
@@ -1,9 +1,11 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/golang/glog" |
|
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 5 | 6 |
"github.com/spf13/cobra" |
| 6 | 7 |
|
| 8 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 7 | 9 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 8 | 10 |
|
| 9 | 11 |
authorizationapi "github.com/openshift/origin/pkg/authorization/api" |
| ... | ... |
@@ -25,23 +27,23 @@ func NewCmdAddGroup(f *clientcmd.Factory) *cobra.Command {
|
| 25 | 25 |
options := &addGroupOptions{}
|
| 26 | 26 |
|
| 27 | 27 |
cmd := &cobra.Command{
|
| 28 |
- Use: "add-role-to-group", |
|
| 28 |
+ Use: "add-role-to-group <role> <group> [group]...", |
|
| 29 | 29 |
Short: "add groups to a role", |
| 30 | 30 |
Long: `add groups to a role`, |
| 31 | 31 |
Run: func(cmd *cobra.Command, args []string) {
|
| 32 |
- if !options.complete(cmd) {
|
|
| 33 |
- return |
|
| 32 |
+ if err := options.complete(args); err != nil {
|
|
| 33 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 34 | 34 |
} |
| 35 | 35 |
|
| 36 | 36 |
var err error |
| 37 | 37 |
if options.client, _, err = f.Clients(); err != nil {
|
| 38 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 38 |
+ kcmdutil.CheckErr(err) |
|
| 39 | 39 |
} |
| 40 | 40 |
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 41 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 41 |
+ kcmdutil.CheckErr(err) |
|
| 42 | 42 |
} |
| 43 | 43 |
if err := options.run(); err != nil {
|
| 44 |
- glog.Fatal(err) |
|
| 44 |
+ kcmdutil.CheckErr(err) |
|
| 45 | 45 |
} |
| 46 | 46 |
}, |
| 47 | 47 |
} |
| ... | ... |
@@ -51,16 +53,14 @@ func NewCmdAddGroup(f *clientcmd.Factory) *cobra.Command {
|
| 51 | 51 |
return cmd |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
-func (o *addGroupOptions) complete(cmd *cobra.Command) bool {
|
|
| 55 |
- args := cmd.Flags().Args() |
|
| 54 |
+func (o *addGroupOptions) complete(args []string) error {
|
|
| 56 | 55 |
if len(args) < 2 {
|
| 57 |
- cmd.Help() |
|
| 58 |
- return false |
|
| 56 |
+ return errors.New("You must specify at least two arguments: <role> <group> [group]...")
|
|
| 59 | 57 |
} |
| 60 | 58 |
|
| 61 | 59 |
o.roleName = args[0] |
| 62 | 60 |
o.groups = args[1:] |
| 63 |
- return true |
|
| 61 |
+ return nil |
|
| 64 | 62 |
} |
| 65 | 63 |
|
| 66 | 64 |
func (o *addGroupOptions) run() error {
|
| ... | ... |
@@ -1,9 +1,11 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/golang/glog" |
|
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 5 | 6 |
"github.com/spf13/cobra" |
| 6 | 7 |
|
| 8 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 7 | 9 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 8 | 10 |
|
| 9 | 11 |
authorizationapi "github.com/openshift/origin/pkg/authorization/api" |
| ... | ... |
@@ -25,23 +27,23 @@ func NewCmdAddUser(f *clientcmd.Factory) *cobra.Command {
|
| 25 | 25 |
options := &AddUserOptions{}
|
| 26 | 26 |
|
| 27 | 27 |
cmd := &cobra.Command{
|
| 28 |
- Use: "add-role-to-user", |
|
| 28 |
+ Use: "add-role-to-user <role> <user> [user]...", |
|
| 29 | 29 |
Short: "add users to a role", |
| 30 | 30 |
Long: `add users to a role`, |
| 31 | 31 |
Run: func(cmd *cobra.Command, args []string) {
|
| 32 |
- if !options.complete(cmd, args) {
|
|
| 33 |
- glog.Fatalf("You must specify two arguments")
|
|
| 32 |
+ if err := options.complete(args); err != nil {
|
|
| 33 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 34 | 34 |
} |
| 35 | 35 |
|
| 36 | 36 |
var err error |
| 37 | 37 |
if options.Client, _, err = f.Clients(); err != nil {
|
| 38 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 38 |
+ kcmdutil.CheckErr(err) |
|
| 39 | 39 |
} |
| 40 | 40 |
if options.BindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 41 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 41 |
+ kcmdutil.CheckErr(err) |
|
| 42 | 42 |
} |
| 43 | 43 |
if err := options.Run(); err != nil {
|
| 44 |
- glog.Fatal(err) |
|
| 44 |
+ kcmdutil.CheckErr(err) |
|
| 45 | 45 |
} |
| 46 | 46 |
}, |
| 47 | 47 |
} |
| ... | ... |
@@ -51,14 +53,14 @@ func NewCmdAddUser(f *clientcmd.Factory) *cobra.Command {
|
| 51 | 51 |
return cmd |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
-func (o *AddUserOptions) complete(cmd *cobra.Command, args []string) bool {
|
|
| 54 |
+func (o *AddUserOptions) complete(args []string) error {
|
|
| 55 | 55 |
if len(args) < 2 {
|
| 56 |
- return false |
|
| 56 |
+ return errors.New("You must specify at least two arguments: <role> <user> [user]...")
|
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
o.RoleName = args[0] |
| 60 | 60 |
o.Users = args[1:] |
| 61 |
- return true |
|
| 61 |
+ return nil |
|
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
func (o *AddUserOptions) Run() error {
|
| ... | ... |
@@ -1,11 +1,13 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
|
| 6 |
- "github.com/golang/glog" |
|
| 7 | 7 |
"github.com/spf13/cobra" |
| 8 | 8 |
|
| 9 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 10 |
+ |
|
| 9 | 11 |
"github.com/openshift/origin/pkg/client" |
| 10 | 12 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| 11 | 13 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| ... | ... |
@@ -28,19 +30,19 @@ func NewCmdRemoveGroup(f *clientcmd.Factory) *cobra.Command {
|
| 28 | 28 |
Short: "remove group from role", |
| 29 | 29 |
Long: `remove group from role`, |
| 30 | 30 |
Run: func(cmd *cobra.Command, args []string) {
|
| 31 |
- if !options.complete(cmd) {
|
|
| 32 |
- return |
|
| 31 |
+ if err := options.complete(args); err != nil {
|
|
| 32 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
var err error |
| 36 | 36 |
if options.Client, _, err = f.Clients(); err != nil {
|
| 37 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 37 |
+ kcmdutil.CheckErr(err) |
|
| 38 | 38 |
} |
| 39 | 39 |
if options.BindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 40 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 40 |
+ kcmdutil.CheckErr(err) |
|
| 41 | 41 |
} |
| 42 | 42 |
if err := options.Run(); err != nil {
|
| 43 |
- glog.Fatal(err) |
|
| 43 |
+ kcmdutil.CheckErr(err) |
|
| 44 | 44 |
} |
| 45 | 45 |
}, |
| 46 | 46 |
} |
| ... | ... |
@@ -50,16 +52,14 @@ func NewCmdRemoveGroup(f *clientcmd.Factory) *cobra.Command {
|
| 50 | 50 |
return cmd |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
-func (o *RemoveGroupOptions) complete(cmd *cobra.Command) bool {
|
|
| 54 |
- args := cmd.Flags().Args() |
|
| 53 |
+func (o *RemoveGroupOptions) complete(args []string) error {
|
|
| 55 | 54 |
if len(args) < 2 {
|
| 56 |
- cmd.Help() |
|
| 57 |
- return false |
|
| 55 |
+ return errors.New("You must specify at least two arguments: <role> <group> [group]...")
|
|
| 58 | 56 |
} |
| 59 | 57 |
|
| 60 | 58 |
o.RoleName = args[0] |
| 61 | 59 |
o.Groups = args[1:] |
| 62 |
- return true |
|
| 60 |
+ return nil |
|
| 63 | 61 |
} |
| 64 | 62 |
|
| 65 | 63 |
func (o *RemoveGroupOptions) Run() error {
|
| ... | ... |
@@ -1,9 +1,12 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/golang/glog" |
|
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 5 | 6 |
"github.com/spf13/cobra" |
| 6 | 7 |
|
| 8 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 9 |
+ |
|
| 7 | 10 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
| 8 | 11 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 9 | 12 |
|
| ... | ... |
@@ -26,20 +29,20 @@ func NewCmdRemoveGroupFromProject(f *clientcmd.Factory) *cobra.Command {
|
| 26 | 26 |
Short: "remove group from project", |
| 27 | 27 |
Long: `remove group from project`, |
| 28 | 28 |
Run: func(cmd *cobra.Command, args []string) {
|
| 29 |
- if !options.complete(cmd) {
|
|
| 30 |
- return |
|
| 29 |
+ if err := options.complete(args); err != nil {
|
|
| 30 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
var err error |
| 34 | 34 |
if options.client, _, err = f.Clients(); err != nil {
|
| 35 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 35 |
+ kcmdutil.CheckErr(err) |
|
| 36 | 36 |
} |
| 37 | 37 |
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 38 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 38 |
+ kcmdutil.CheckErr(err) |
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
if err := options.run(); err != nil {
|
| 42 |
- glog.Fatal(err) |
|
| 42 |
+ kcmdutil.CheckErr(err) |
|
| 43 | 43 |
} |
| 44 | 44 |
}, |
| 45 | 45 |
} |
| ... | ... |
@@ -47,15 +50,13 @@ func NewCmdRemoveGroupFromProject(f *clientcmd.Factory) *cobra.Command {
|
| 47 | 47 |
return cmd |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 |
-func (o *removeGroupFromProjectOptions) complete(cmd *cobra.Command) bool {
|
|
| 51 |
- args := cmd.Flags().Args() |
|
| 50 |
+func (o *removeGroupFromProjectOptions) complete(args []string) error {
|
|
| 52 | 51 |
if len(args) < 1 {
|
| 53 |
- cmd.Help() |
|
| 54 |
- return false |
|
| 52 |
+ return errors.New("You must specify at least one argument: <group> [group]...")
|
|
| 55 | 53 |
} |
| 56 | 54 |
|
| 57 | 55 |
o.groups = args |
| 58 |
- return true |
|
| 56 |
+ return nil |
|
| 59 | 57 |
} |
| 60 | 58 |
|
| 61 | 59 |
func (o *removeGroupFromProjectOptions) run() error {
|
| ... | ... |
@@ -1,11 +1,13 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
|
| 6 |
- "github.com/golang/glog" |
|
| 7 | 7 |
"github.com/spf13/cobra" |
| 8 | 8 |
|
| 9 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 10 |
+ |
|
| 9 | 11 |
"github.com/openshift/origin/pkg/client" |
| 10 | 12 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| 11 | 13 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| ... | ... |
@@ -28,19 +30,19 @@ func NewCmdRemoveUser(f *clientcmd.Factory) *cobra.Command {
|
| 28 | 28 |
Short: "remove user from role", |
| 29 | 29 |
Long: `remove user from role`, |
| 30 | 30 |
Run: func(cmd *cobra.Command, args []string) {
|
| 31 |
- if !options.complete(cmd) {
|
|
| 32 |
- return |
|
| 31 |
+ if err := options.complete(args); err != nil {
|
|
| 32 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
var err error |
| 36 | 36 |
if options.client, _, err = f.Clients(); err != nil {
|
| 37 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 37 |
+ kcmdutil.CheckErr(err) |
|
| 38 | 38 |
} |
| 39 | 39 |
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 40 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 40 |
+ kcmdutil.CheckErr(err) |
|
| 41 | 41 |
} |
| 42 | 42 |
if err := options.run(); err != nil {
|
| 43 |
- glog.Fatal(err) |
|
| 43 |
+ kcmdutil.CheckErr(err) |
|
| 44 | 44 |
} |
| 45 | 45 |
}, |
| 46 | 46 |
} |
| ... | ... |
@@ -50,16 +52,14 @@ func NewCmdRemoveUser(f *clientcmd.Factory) *cobra.Command {
|
| 50 | 50 |
return cmd |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
-func (o *removeUserOptions) complete(cmd *cobra.Command) bool {
|
|
| 54 |
- args := cmd.Flags().Args() |
|
| 53 |
+func (o *removeUserOptions) complete(args []string) error {
|
|
| 55 | 54 |
if len(args) < 2 {
|
| 56 |
- cmd.Help() |
|
| 57 |
- return false |
|
| 55 |
+ return errors.New("You must specify at least two arguments: <role> <user> [user]...")
|
|
| 58 | 56 |
} |
| 59 | 57 |
|
| 60 | 58 |
o.roleName = args[0] |
| 61 | 59 |
o.users = args[1:] |
| 62 |
- return true |
|
| 60 |
+ return nil |
|
| 63 | 61 |
} |
| 64 | 62 |
|
| 65 | 63 |
func (o *removeUserOptions) run() error {
|
| ... | ... |
@@ -1,10 +1,12 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/golang/glog" |
|
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 5 | 6 |
"github.com/spf13/cobra" |
| 6 | 7 |
|
| 7 | 8 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
| 9 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 8 | 10 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 9 | 11 |
|
| 10 | 12 |
"github.com/openshift/origin/pkg/client" |
| ... | ... |
@@ -26,19 +28,19 @@ func NewCmdRemoveUserFromProject(f *clientcmd.Factory) *cobra.Command {
|
| 26 | 26 |
Short: "remove user from project", |
| 27 | 27 |
Long: `remove user from project`, |
| 28 | 28 |
Run: func(cmd *cobra.Command, args []string) {
|
| 29 |
- if !options.complete(cmd) {
|
|
| 30 |
- return |
|
| 29 |
+ if err := options.complete(args); err != nil {
|
|
| 30 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
var err error |
| 34 | 34 |
if options.client, _, err = f.Clients(); err != nil {
|
| 35 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 35 |
+ kcmdutil.CheckErr(err) |
|
| 36 | 36 |
} |
| 37 | 37 |
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 38 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 38 |
+ kcmdutil.CheckErr(err) |
|
| 39 | 39 |
} |
| 40 | 40 |
if err := options.run(); err != nil {
|
| 41 |
- glog.Fatal(err) |
|
| 41 |
+ kcmdutil.CheckErr(err) |
|
| 42 | 42 |
} |
| 43 | 43 |
}, |
| 44 | 44 |
} |
| ... | ... |
@@ -46,15 +48,13 @@ func NewCmdRemoveUserFromProject(f *clientcmd.Factory) *cobra.Command {
|
| 46 | 46 |
return cmd |
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 |
-func (o *removeUserFromProjectOptions) complete(cmd *cobra.Command) bool {
|
|
| 50 |
- args := cmd.Flags().Args() |
|
| 49 |
+func (o *removeUserFromProjectOptions) complete(args []string) error {
|
|
| 51 | 50 |
if len(args) < 1 {
|
| 52 |
- cmd.Help() |
|
| 53 |
- return false |
|
| 51 |
+ return errors.New("You must specify at least one argument: <user> [user]...")
|
|
| 54 | 52 |
} |
| 55 | 53 |
|
| 56 | 54 |
o.users = args |
| 57 |
- return true |
|
| 55 |
+ return nil |
|
| 58 | 56 |
} |
| 59 | 57 |
|
| 60 | 58 |
func (o *removeUserFromProjectOptions) run() error {
|
| ... | ... |
@@ -1,12 +1,14 @@ |
| 1 | 1 |
package policy |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"strings" |
| 6 | 7 |
|
| 7 |
- "github.com/golang/glog" |
|
| 8 | 8 |
"github.com/spf13/cobra" |
| 9 | 9 |
|
| 10 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 11 |
+ |
|
| 10 | 12 |
authorizationapi "github.com/openshift/origin/pkg/authorization/api" |
| 11 | 13 |
"github.com/openshift/origin/pkg/client" |
| 12 | 14 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| ... | ... |
@@ -24,23 +26,23 @@ func NewCmdWhoCan(f *clientcmd.Factory) *cobra.Command {
|
| 24 | 24 |
options := &whoCanOptions{}
|
| 25 | 25 |
|
| 26 | 26 |
cmd := &cobra.Command{
|
| 27 |
- Use: "who-can", |
|
| 27 |
+ Use: "who-can <verb> <resource>", |
|
| 28 | 28 |
Short: "who-can <verb> <resource>", |
| 29 | 29 |
Long: `who-can <verb> <resource>`, |
| 30 | 30 |
Run: func(cmd *cobra.Command, args []string) {
|
| 31 |
- if !options.complete(cmd) {
|
|
| 32 |
- return |
|
| 31 |
+ if err := options.complete(args); err != nil {
|
|
| 32 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
var err error |
| 36 | 36 |
if options.client, _, err = f.Clients(); err != nil {
|
| 37 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 37 |
+ kcmdutil.CheckErr(err) |
|
| 38 | 38 |
} |
| 39 | 39 |
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
|
| 40 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 40 |
+ kcmdutil.CheckErr(err) |
|
| 41 | 41 |
} |
| 42 | 42 |
if err := options.run(); err != nil {
|
| 43 |
- glog.Fatal(err) |
|
| 43 |
+ kcmdutil.CheckErr(err) |
|
| 44 | 44 |
} |
| 45 | 45 |
}, |
| 46 | 46 |
} |
| ... | ... |
@@ -48,16 +50,14 @@ func NewCmdWhoCan(f *clientcmd.Factory) *cobra.Command {
|
| 48 | 48 |
return cmd |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
-func (o *whoCanOptions) complete(cmd *cobra.Command) bool {
|
|
| 52 |
- args := cmd.Flags().Args() |
|
| 51 |
+func (o *whoCanOptions) complete(args []string) error {
|
|
| 53 | 52 |
if len(args) != 2 {
|
| 54 |
- cmd.Help() |
|
| 55 |
- return false |
|
| 53 |
+ return errors.New("You must specify two arguments: <verb> <resource>")
|
|
| 56 | 54 |
} |
| 57 | 55 |
|
| 58 | 56 |
o.verb = args[0] |
| 59 | 57 |
o.resource = args[1] |
| 60 |
- return true |
|
| 58 |
+ return nil |
|
| 61 | 59 |
} |
| 62 | 60 |
|
| 63 | 61 |
func (o *whoCanOptions) run() error {
|
| ... | ... |
@@ -1,12 +1,13 @@ |
| 1 | 1 |
package project |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
|
| 6 |
- "github.com/golang/glog" |
|
| 7 | 7 |
"github.com/spf13/cobra" |
| 8 | 8 |
|
| 9 | 9 |
kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
| 10 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 10 | 11 |
|
| 11 | 12 |
"github.com/openshift/origin/pkg/client" |
| 12 | 13 |
"github.com/openshift/origin/pkg/cmd/experimental/policy" |
| ... | ... |
@@ -35,16 +36,16 @@ func NewCmdNewProject(f *clientcmd.Factory, parentName, name string) *cobra.Comm |
| 35 | 35 |
Short: "create a new project", |
| 36 | 36 |
Long: `create a new project`, |
| 37 | 37 |
Run: func(cmd *cobra.Command, args []string) {
|
| 38 |
- if !options.complete(cmd) {
|
|
| 39 |
- return |
|
| 38 |
+ if err := options.complete(args); err != nil {
|
|
| 39 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 | 42 |
var err error |
| 43 | 43 |
if options.Client, _, err = f.Clients(); err != nil {
|
| 44 |
- glog.Fatalf("Error getting client: %v", err)
|
|
| 44 |
+ kcmdutil.CheckErr(err) |
|
| 45 | 45 |
} |
| 46 | 46 |
if err := options.Run(); err != nil {
|
| 47 |
- glog.Fatal(err) |
|
| 47 |
+ kcmdutil.CheckErr(err) |
|
| 48 | 48 |
} |
| 49 | 49 |
}, |
| 50 | 50 |
} |
| ... | ... |
@@ -59,16 +60,13 @@ func NewCmdNewProject(f *clientcmd.Factory, parentName, name string) *cobra.Comm |
| 59 | 59 |
return cmd |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
-func (o *NewProjectOptions) complete(cmd *cobra.Command) bool {
|
|
| 63 |
- args := cmd.Flags().Args() |
|
| 62 |
+func (o *NewProjectOptions) complete(args []string) error {
|
|
| 64 | 63 |
if len(args) != 1 {
|
| 65 |
- cmd.Help() |
|
| 66 |
- return false |
|
| 64 |
+ return errors.New("You must specify one argument: <project-name>")
|
|
| 67 | 65 |
} |
| 68 | 66 |
|
| 69 | 67 |
o.ProjectName = args[0] |
| 70 |
- |
|
| 71 |
- return true |
|
| 68 |
+ return nil |
|
| 72 | 69 |
} |
| 73 | 70 |
|
| 74 | 71 |
func (o *NewProjectOptions) Run() error {
|
| ... | ... |
@@ -3,17 +3,16 @@ package admin |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"errors" |
| 6 |
- "fmt" |
|
| 7 | 6 |
"io" |
| 8 | 7 |
"io/ioutil" |
| 9 | 8 |
"os" |
| 10 | 9 |
"path" |
| 11 | 10 |
|
| 12 |
- "github.com/golang/glog" |
|
| 13 | 11 |
"github.com/spf13/cobra" |
| 14 | 12 |
|
| 15 | 13 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 16 | 14 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl" |
| 15 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 17 | 16 |
|
| 18 | 17 |
"github.com/openshift/origin/pkg/api/latest" |
| 19 | 18 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| ... | ... |
@@ -39,15 +38,13 @@ func NewCommandCreateBootstrapPolicyFile(commandName string, fullName string, ou |
| 39 | 39 |
cmd := &cobra.Command{
|
| 40 | 40 |
Use: commandName, |
| 41 | 41 |
Short: "Create bootstrap policy for OpenShift.", |
| 42 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 42 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 43 | 43 |
if err := options.Validate(args); err != nil {
|
| 44 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 45 |
- c.Help() |
|
| 46 |
- return |
|
| 44 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 47 | 45 |
} |
| 48 | 46 |
|
| 49 | 47 |
if err := options.CreateBootstrapPolicyFile(); err != nil {
|
| 50 |
- glog.Fatal(err) |
|
| 48 |
+ kcmdutil.CheckErr(err) |
|
| 51 | 49 |
} |
| 52 | 50 |
}, |
| 53 | 51 |
} |
| ... | ... |
@@ -2,7 +2,6 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"path" |
| ... | ... |
@@ -11,6 +10,7 @@ import ( |
| 11 | 11 |
"github.com/spf13/cobra" |
| 12 | 12 |
|
| 13 | 13 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 14 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 14 | 15 |
|
| 15 | 16 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 16 | 17 |
) |
| ... | ... |
@@ -36,15 +36,13 @@ func NewCommandCreateClient(commandName string, fullName string, out io.Writer) |
| 36 | 36 |
cmd := &cobra.Command{
|
| 37 | 37 |
Use: commandName, |
| 38 | 38 |
Short: "Create a portable client folder containing a client certificate, a client key, a server certificate authority, and a .kubeconfig file.", |
| 39 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 39 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 40 | 40 |
if err := options.Validate(args); err != nil {
|
| 41 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 42 |
- c.Help() |
|
| 43 |
- return |
|
| 41 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 44 | 42 |
} |
| 45 | 43 |
|
| 46 | 44 |
if err := options.CreateClientFolder(); err != nil {
|
| 47 |
- glog.Fatal(err) |
|
| 45 |
+ kcmdutil.CheckErr(err) |
|
| 48 | 46 |
} |
| 49 | 47 |
}, |
| 50 | 48 |
} |
| ... | ... |
@@ -2,7 +2,6 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"os" |
| ... | ... |
@@ -12,6 +11,7 @@ import ( |
| 12 | 12 |
"github.com/spf13/cobra" |
| 13 | 13 |
|
| 14 | 14 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 15 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 15 | 16 |
|
| 16 | 17 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd" |
| 17 | 18 |
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api" |
| ... | ... |
@@ -72,15 +72,13 @@ users: |
| 72 | 72 |
client-certificate-data: <contents of --client-certificate> |
| 73 | 73 |
client-key-data: <contents of --client-key> |
| 74 | 74 |
`, |
| 75 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 75 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 76 | 76 |
if err := options.Validate(args); err != nil {
|
| 77 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 78 |
- c.Help() |
|
| 79 |
- return |
|
| 77 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 80 | 78 |
} |
| 81 | 79 |
|
| 82 | 80 |
if _, err := options.CreateKubeConfig(); err != nil {
|
| 83 |
- glog.Fatal(err) |
|
| 81 |
+ kcmdutil.CheckErr(err) |
|
| 84 | 82 |
} |
| 85 | 83 |
}, |
| 86 | 84 |
} |
| ... | ... |
@@ -2,7 +2,6 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
"path" |
| 8 | 7 |
"path/filepath" |
| ... | ... |
@@ -11,6 +10,7 @@ import ( |
| 11 | 11 |
"github.com/spf13/cobra" |
| 12 | 12 |
|
| 13 | 13 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 14 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 14 | 15 |
|
| 15 | 16 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 16 | 17 |
) |
| ... | ... |
@@ -35,15 +35,13 @@ func NewCommandCreateMasterCerts(commandName string, fullName string, out io.Wri |
| 35 | 35 |
cmd := &cobra.Command{
|
| 36 | 36 |
Use: commandName, |
| 37 | 37 |
Short: "Create all certificates for an OpenShift master. To create node certificates, try openshift admin create-node-config", |
| 38 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 38 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 39 | 39 |
if err := options.Validate(args); err != nil {
|
| 40 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 41 |
- c.Help() |
|
| 42 |
- return |
|
| 40 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 43 | 41 |
} |
| 44 | 42 |
|
| 45 | 43 |
if err := options.CreateMasterCerts(); err != nil {
|
| 46 |
- glog.Fatal(err) |
|
| 44 |
+ kcmdutil.CheckErr(err) |
|
| 47 | 45 |
} |
| 48 | 46 |
}, |
| 49 | 47 |
} |
| ... | ... |
@@ -2,7 +2,6 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"net" |
| ... | ... |
@@ -10,11 +9,11 @@ import ( |
| 10 | 10 |
"path" |
| 11 | 11 |
"strconv" |
| 12 | 12 |
|
| 13 |
- "github.com/golang/glog" |
|
| 14 | 13 |
"github.com/spf13/cobra" |
| 15 | 14 |
|
| 16 | 15 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 17 | 16 |
klatest "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" |
| 17 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 18 | 18 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" |
| 19 | 19 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 20 | 20 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| ... | ... |
@@ -57,15 +56,13 @@ func NewCommandNodeConfig(commandName string, fullName string, out io.Writer) *c |
| 57 | 57 |
cmd := &cobra.Command{
|
| 58 | 58 |
Use: commandName, |
| 59 | 59 |
Short: "Create a portable client folder containing a client certificate, a client key, a server certificate authority, and a .kubeconfig file.", |
| 60 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 60 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 61 | 61 |
if err := options.Validate(args); err != nil {
|
| 62 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 63 |
- c.Help() |
|
| 64 |
- return |
|
| 62 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 65 | 63 |
} |
| 66 | 64 |
|
| 67 | 65 |
if err := options.CreateNodeFolder(); err != nil {
|
| 68 |
- glog.Fatal(err) |
|
| 66 |
+ kcmdutil.CheckErr(err) |
|
| 69 | 67 |
} |
| 70 | 68 |
}, |
| 71 | 69 |
} |
| ... | ... |
@@ -2,12 +2,12 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
|
| 8 | 7 |
"github.com/golang/glog" |
| 9 | 8 |
"github.com/spf13/cobra" |
| 10 | 9 |
|
| 10 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 11 | 11 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/openshift/origin/pkg/cmd/server/crypto" |
| ... | ... |
@@ -31,15 +31,13 @@ func NewCommandCreateServerCert(commandName string, fullName string, out io.Writ |
| 31 | 31 |
cmd := &cobra.Command{
|
| 32 | 32 |
Use: commandName, |
| 33 | 33 |
Short: "Create server certificate", |
| 34 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 34 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 35 | 35 |
if err := options.Validate(args); err != nil {
|
| 36 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 37 |
- c.Help() |
|
| 38 |
- return |
|
| 36 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 39 | 37 |
} |
| 40 | 38 |
|
| 41 | 39 |
if _, err := options.CreateServerCert(); err != nil {
|
| 42 |
- glog.Fatal(err) |
|
| 40 |
+ kcmdutil.CheckErr(err) |
|
| 43 | 41 |
} |
| 44 | 42 |
}, |
| 45 | 43 |
} |
| ... | ... |
@@ -2,13 +2,14 @@ package admin |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
|
| 8 | 7 |
"github.com/golang/glog" |
| 9 | 8 |
"github.com/spf13/cobra" |
| 10 | 9 |
"github.com/spf13/pflag" |
| 11 | 10 |
|
| 11 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 12 |
+ |
|
| 12 | 13 |
"github.com/openshift/origin/pkg/cmd/server/crypto" |
| 13 | 14 |
) |
| 14 | 15 |
|
| ... | ... |
@@ -37,15 +38,13 @@ func NewCommandCreateSignerCert(commandName string, fullName string, out io.Writ |
| 37 | 37 |
cmd := &cobra.Command{
|
| 38 | 38 |
Use: commandName, |
| 39 | 39 |
Short: "Create signer certificate", |
| 40 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 40 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 41 | 41 |
if err := options.Validate(args); err != nil {
|
| 42 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 43 |
- c.Help() |
|
| 44 |
- return |
|
| 42 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 45 | 43 |
} |
| 46 | 44 |
|
| 47 | 45 |
if _, err := options.CreateSignerCert(); err != nil {
|
| 48 |
- glog.Fatal(err) |
|
| 46 |
+ kcmdutil.CheckErr(err) |
|
| 49 | 47 |
} |
| 50 | 48 |
}, |
| 51 | 49 |
} |
| ... | ... |
@@ -6,12 +6,12 @@ import ( |
| 6 | 6 |
"io" |
| 7 | 7 |
|
| 8 | 8 |
etcdclient "github.com/coreos/go-etcd/etcd" |
| 9 |
- "github.com/golang/glog" |
|
| 10 | 9 |
"github.com/spf13/cobra" |
| 11 | 10 |
|
| 12 | 11 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 13 | 12 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta" |
| 14 | 13 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl" |
| 14 |
+ kcmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" |
|
| 15 | 15 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource" |
| 16 | 16 |
utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors" |
| 17 | 17 |
|
| ... | ... |
@@ -50,15 +50,13 @@ func NewCommandOverwriteBootstrapPolicy(commandName string, fullName string, cre |
| 50 | 50 |
cmd := &cobra.Command{
|
| 51 | 51 |
Use: commandName, |
| 52 | 52 |
Short: "Reset the policy to the default values", |
| 53 |
- Run: func(c *cobra.Command, args []string) {
|
|
| 53 |
+ Run: func(cmd *cobra.Command, args []string) {
|
|
| 54 | 54 |
if err := options.Validate(args); err != nil {
|
| 55 |
- fmt.Fprintln(c.Out(), err.Error()) |
|
| 56 |
- c.Help() |
|
| 57 |
- return |
|
| 55 |
+ kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error())) |
|
| 58 | 56 |
} |
| 59 | 57 |
|
| 60 | 58 |
if err := options.OverwriteBootstrapPolicy(); err != nil {
|
| 61 |
- glog.Fatal(err) |
|
| 59 |
+ kcmdutil.CheckErr(err) |
|
| 62 | 60 |
} |
| 63 | 61 |
}, |
| 64 | 62 |
} |