implement ocdev application list

This commit is contained in:
Shubham Minglani
2018-02-05 18:50:52 +05:30
parent 6bf64ba610
commit b04213c71c
3 changed files with 34 additions and 0 deletions

View File

@@ -60,9 +60,24 @@ var getCmd = &cobra.Command{
},
}
var listCmd = &cobra.Command{
Use: "list",
Short: "lists all the applications",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
app, err := application.List()
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Print(app)
},
}
func init() {
getCmd.Flags().BoolVarP(&isQuiet, "short", "q", false, "If true, display only the application name")
applicationCmd.AddCommand(listCmd)
applicationCmd.AddCommand(getCmd)
applicationCmd.AddCommand(createCmd)
rootCmd.AddCommand(applicationCmd)

View File

@@ -28,6 +28,14 @@ func Create(name string) error {
return nil
}
func List() (string, error) {
project, err := occlient.GetProjects()
if err != nil {
return "", errors.Wrap(err, "unable to list applications")
}
return project, nil
}
func GetCurrent() (string, error) {
app, err := occlient.GetCurrentProjectName()
if err != nil {

View File

@@ -147,6 +147,17 @@ func GetCurrentProjectName() (string, error) {
return strings.TrimSpace(string(output)), nil
}
func GetProjects() (string, error) {
output, err := runOcComamnd(&OcCommand{
args: []string{"get", "project"},
format: "custom-columns=NAME:.metadata.name",
})
if err != nil {
return "", errors.Wrap(err, "unable to get projects")
}
return string(output), nil
}
func CreateNewProject(name string) error {
_, err := runOcComamnd(&OcCommand{
args: []string{"new-project", name},