Skip to content

Commit

Permalink
Introduce list service instances command (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyordanoff authored Dec 3, 2019
1 parent 12eb0df commit 0759dff
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 31 deletions.
71 changes: 44 additions & 27 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions internal/cmd/instance/list_instances.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2018 The Service Manager Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package instance

import (
"github.com/Peripli/service-manager-cli/internal/cmd"
"github.com/Peripli/service-manager-cli/internal/output"
"github.com/spf13/cobra"
)

// ListInstancesCmd wraps the smctl list-instances command
type ListInstancesCmd struct {
*cmd.Context

outputFormat output.Format
}

// NewListInstancesCmd returns new list-instances command with context
func NewListInstancesCmd(context *cmd.Context) *ListInstancesCmd {
return &ListInstancesCmd{Context: context}
}

// Run runs the command's logic
func (li *ListInstancesCmd) Run() error {
instances, err := li.Client.ListInstances(&li.Parameters)
if err != nil {
return err
}

output.PrintServiceManagerObject(li.Output, li.outputFormat, instances)
output.Println(li.Output)

return nil
}

// SetOutputFormat sets output format
func (li *ListInstancesCmd) SetOutputFormat(format output.Format) {
li.outputFormat = format
}

// HideUsage hides command's usage
func (li *ListInstancesCmd) HideUsage() bool {
return true
}

// Prepare returns cobra command
func (li *ListInstancesCmd) Prepare(prepare cmd.PrepareFunc) *cobra.Command {
result := &cobra.Command{
Use: "list-instances",
Aliases: []string{"li"},
Short: "List service-instances",
Long: `List all service-instances.`,
PreRunE: prepare(li, li.Context),
RunE: cmd.RunE(li),
}

cmd.AddFormatFlag(result.Flags())
cmd.AddQueryingFlags(result.Flags(), &li.Parameters)
cmd.AddCommonQueryFlag(result.Flags(), &li.Parameters)

return result
}
Loading

0 comments on commit 0759dff

Please sign in to comment.