mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Merge pull request #33 from containscafeine/implement-application-list
implement `ocdev application list`
This commit is contained in:
15
cmd/app.go
15
cmd/app.go
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user