Skip to content

Commit 66c4c57

Browse files
Maxime MENAGERmaximemenager
Maxime MENAGER
authored andcommitted
Move apps-versions CLI from instances to apps
1 parent 2dff7ef commit 66c4c57

5 files changed

+44
-39
lines changed

cmd/apps.go

+36
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import (
99
"text/tabwriter"
1010

1111
"github.com/cozy/cozy-stack/client"
12+
"github.com/cozy/cozy-stack/pkg/apps"
1213
"github.com/cozy/cozy-stack/pkg/config"
1314
"github.com/cozy/cozy-stack/pkg/consts"
15+
"github.com/cozy/cozy-stack/pkg/couchdb"
16+
"github.com/cozy/cozy-stack/pkg/instance"
1417
"github.com/spf13/cobra"
1518
)
1619

@@ -559,6 +562,38 @@ func lsApps(cmd *cobra.Command, args []string, appType string) error {
559562
return w.Flush()
560563
}
561564

565+
var appsVersionsCmd = &cobra.Command{
566+
Use: "versions",
567+
Short: `Show apps versions of all instances`,
568+
Example: "$ cozy-stack apps versions",
569+
RunE: func(cmd *cobra.Command, args []string) error {
570+
instances, err := instance.List()
571+
if err != nil {
572+
return nil
573+
}
574+
counter := make(map[string]map[string]int)
575+
576+
for _, instance := range instances {
577+
var apps []*apps.WebappManifest
578+
req := &couchdb.AllDocsRequest{Limit: 100}
579+
couchdb.GetAllDocs(instance, consts.Apps, req, &apps)
580+
581+
for _, app := range apps {
582+
if _, ok := counter[app.Slug()]; !ok {
583+
counter[app.Slug()] = map[string]int{app.Version(): 0}
584+
}
585+
counter[app.Slug()][app.Version()]++
586+
}
587+
}
588+
json, err := json.MarshalIndent(counter, "", " ")
589+
if err != nil {
590+
return err
591+
}
592+
fmt.Println(string(json))
593+
return nil
594+
},
595+
}
596+
562597
func foreachDomains(predicate func(*client.Instance) error) error {
563598
c := newAdminClient()
564599
// TODO(pagination): Make this iteration more robust
@@ -602,6 +637,7 @@ func init() {
602637
webappsCmdGroup.AddCommand(installWebappCmd)
603638
webappsCmdGroup.AddCommand(updateWebappCmd)
604639
webappsCmdGroup.AddCommand(uninstallWebappCmd)
640+
webappsCmdGroup.AddCommand(appsVersionsCmd)
605641

606642
konnectorsCmdGroup.PersistentFlags().StringVar(&flagAppsDomain, "domain", domain, "specify the domain name of the instance")
607643
konnectorsCmdGroup.PersistentFlags().StringVar(&flagKonnectorsParameters, "parameters", "", "override the parameters of the installed konnector")

cmd/instances.go

-33
Original file line numberDiff line numberDiff line change
@@ -839,38 +839,6 @@ var showSwiftPrefixInstanceCmd = &cobra.Command{
839839
},
840840
}
841841

842-
var appsVersionsCmd = &cobra.Command{
843-
Use: "apps-versions",
844-
Short: `Show apps versions of all instances`,
845-
Example: "$ cozy-stack instances apps-versions",
846-
RunE: func(cmd *cobra.Command, args []string) error {
847-
instances, err := instance.List()
848-
if err != nil {
849-
return nil
850-
}
851-
counter := make(map[string]map[string]int)
852-
853-
for _, instance := range instances {
854-
var apps []*apps.WebappManifest
855-
req := &couchdb.AllDocsRequest{Limit: 100}
856-
couchdb.GetAllDocs(instance, consts.Apps, req, &apps)
857-
858-
for _, app := range apps {
859-
if _, ok := counter[app.Slug()]; !ok {
860-
counter[app.Slug()] = map[string]int{app.Version(): 0}
861-
}
862-
counter[app.Slug()][app.Version()]++
863-
}
864-
}
865-
json, err := json.MarshalIndent(counter, "", " ")
866-
if err != nil {
867-
return err
868-
}
869-
fmt.Println(string(json))
870-
return nil
871-
},
872-
}
873-
874842
var instanceAppVersionCmd = &cobra.Command{
875843
Use: "show-app-version [app-slug] [version]",
876844
Short: `Show instances that have a particular app version`,
@@ -933,7 +901,6 @@ func init() {
933901
instanceCmdGroup.AddCommand(exportCmd)
934902
instanceCmdGroup.AddCommand(importCmd)
935903
instanceCmdGroup.AddCommand(showSwiftPrefixInstanceCmd)
936-
instanceCmdGroup.AddCommand(appsVersionsCmd)
937904
instanceCmdGroup.AddCommand(instanceAppVersionCmd)
938905
addInstanceCmd.Flags().StringSliceVar(&flagDomainAliases, "domain-aliases", nil, "Specify one or more aliases domain for the instance (separated by ',')")
939906
addInstanceCmd.Flags().StringVar(&flagLocale, "locale", instance.DefaultLocale, "Locale of the new cozy instance")

docs/cli/cozy-stack_apps.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ from the given source URL.
4242
* [cozy-stack apps show](cozy-stack_apps_show.md) - Show the application attributes
4343
* [cozy-stack apps uninstall](cozy-stack_apps_uninstall.md) - Uninstall the application with the specified slug name.
4444
* [cozy-stack apps update](cozy-stack_apps_update.md) - Update the application with the specified slug name.
45+
* [cozy-stack apps versions](cozy-stack_apps_versions.md) - Show apps versions of all instances
4546

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## cozy-stack instances apps-versions
1+
## cozy-stack apps versions
22

33
Show apps versions of all instances
44

@@ -7,32 +7,34 @@ Show apps versions of all instances
77
Show apps versions of all instances
88

99
```
10-
cozy-stack instances apps-versions [flags]
10+
cozy-stack apps versions [flags]
1111
```
1212

1313
### Examples
1414

1515
```
16-
$ cozy-stack instances apps-versions
16+
$ cozy-stack apps versions
1717
```
1818

1919
### Options
2020

2121
```
22-
-h, --help help for apps-versions
22+
-h, --help help for versions
2323
```
2424

2525
### Options inherited from parent commands
2626

2727
```
2828
--admin-host string administration server host (default "localhost")
2929
--admin-port int administration server port (default 6060)
30+
--all-domains work on all domains iterativelly
3031
-c, --config string configuration file (default "$HOME/.cozy.yaml")
32+
--domain string specify the domain name of the instance (default "cozy.tools:8080")
3133
--host string server host (default "localhost")
3234
-p, --port int server port (default 8080)
3335
```
3436

3537
### SEE ALSO
3638

37-
* [cozy-stack instances](cozy-stack_instances.md) - Manage instances of a stack
39+
* [cozy-stack apps](cozy-stack_apps.md) - Interact with the applications
3840

docs/cli/cozy-stack_instances.md

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ cozy-stack instances <command> [flags]
3939

4040
* [cozy-stack](cozy-stack.md) - cozy-stack is the main command
4141
* [cozy-stack instances add](cozy-stack_instances_add.md) - Manage instances of a stack
42-
* [cozy-stack instances apps-versions](cozy-stack_instances_apps-versions.md) - Show apps versions of all instances
4342
* [cozy-stack instances client-oauth](cozy-stack_instances_client-oauth.md) - Register a new OAuth client
4443
* [cozy-stack instances debug](cozy-stack_instances_debug.md) - Activate or deactivate debugging of the instance
4544
* [cozy-stack instances destroy](cozy-stack_instances_destroy.md) - Remove instance

0 commit comments

Comments
 (0)