Skip to content

Commit 7c0f87a

Browse files
authored
Merge pull request #2318 from nono/improve-cli
Improve CLI
2 parents f107287 + 5b71ba1 commit 7c0f87a

File tree

16 files changed

+143
-17
lines changed

16 files changed

+143
-17
lines changed

cmd/fixer.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,36 @@ done, the konnector is uninstalled again.
376376
if len(args) != 1 {
377377
return cmd.Usage()
378378
}
379-
380379
domain := args[0]
381-
382380
c := newAdminClient()
383381
path := fmt.Sprintf("/instances/%s/fixers/orphan-account", domain)
384382
_, err := c.Req(&request.Options{
385383
Method: "POST",
386384
Path: path,
387385
})
388-
if err != nil {
389-
return err
390-
}
386+
return err
387+
},
388+
}
391389

392-
return nil
390+
var indexesFixer = &cobra.Command{
391+
Use: "indexes <domain>",
392+
Short: "Rebuild the CouchDB views and indexes",
393+
Long: `
394+
This fixer ensures that the CouchDB views and indexes used by the stack for
395+
this instance are correctly set.
396+
`,
397+
RunE: func(cmd *cobra.Command, args []string) error {
398+
if len(args) != 1 {
399+
return cmd.Usage()
400+
}
401+
domain := args[0]
402+
c := newAdminClient()
403+
path := fmt.Sprintf("/instances/%s/fixers/indexes", domain)
404+
_, err := c.Req(&request.Options{
405+
Method: "POST",
406+
Path: path,
407+
})
408+
return err
393409
},
394410
}
395411

@@ -406,6 +422,7 @@ func init() {
406422
fixerCmdGroup.AddCommand(contactEmailsFixer)
407423
fixerCmdGroup.AddCommand(contentMismatch64Kfixer)
408424
fixerCmdGroup.AddCommand(orphanAccountFixer)
425+
fixerCmdGroup.AddCommand(indexesFixer)
409426

410427
RootCmd.AddCommand(fixerCmdGroup)
411428
}

cmd/serve.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
var flagAllowRoot bool
2525
var flagAppdirs []string
2626
var flagDevMode bool
27+
var flagMailhog bool
2728

2829
// serveCmd represents the serve command
2930
var serveCmd = &cobra.Command{
@@ -82,6 +83,12 @@ example), you can use the --appdir flag like this:
8283
}
8384
}
8485

86+
if flagMailhog {
87+
cfg := config.GetConfig()
88+
cfg.Mail.DisableTLS = true
89+
cfg.Mail.Port = 1025
90+
}
91+
8592
processes, err := stack.Start()
8693
if err != nil {
8794
return err
@@ -213,6 +220,7 @@ func init() {
213220
flags.String("password-reset-interval", "15m", "minimal duration between two password reset")
214221
checkNoErr(viper.BindPFlag("password_reset_interval", flags.Lookup("password-reset-interval")))
215222

223+
flags.BoolVar(&flagMailhog, "mailhog", false, "Alias of --mail-disable-tls --mail-port 1025, useful for MailHog")
216224
flags.BoolVar(&flagDevMode, "dev", false, "Allow to run in dev mode for a prod release (disabled by default)")
217225
flags.BoolVar(&flagAllowRoot, "allow-root", false, "Allow to start as root (disabled by default)")
218226
flags.StringSliceVar(&flagAppdirs, "appdir", nil, "Mount a directory as the 'app' application")

docs/cli/cozy-stack_features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Manage the feature flags
2525
### SEE ALSO
2626

2727
* [cozy-stack](cozy-stack.md) - cozy-stack is the main command
28-
* [cozy-stack features context](cozy-stack_features_context.md) - Display and update the feature flags for a context
2928
* [cozy-stack features defaults](cozy-stack_features_defaults.md) - Display and update the default values for feature flags
3029
* [cozy-stack features flags](cozy-stack_features_flags.md) - Display and update the feature flags for an instance
30+
* [cozy-stack features ratio](cozy-stack_features_ratio.md) - Display and update the feature flags for a context
3131
* [cozy-stack features sets](cozy-stack_features_sets.md) - Display and update the feature sets for an instance
3232
* [cozy-stack features show](cozy-stack_features_show.md) - Display the computed feature flags for an instance
3333

docs/cli/cozy-stack_features_context.md renamed to docs/cli/cozy-stack_features_ratio.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## cozy-stack features context
1+
## cozy-stack features ratio
22

33
Display and update the feature flags for a context
44

@@ -13,7 +13,7 @@ To remove a flag, set it to an empty array (or null).
1313

1414

1515
```
16-
cozy-stack features context <context-name> [flags]
16+
cozy-stack features ratio <context-name> [flags]
1717
```
1818

1919
### Examples
@@ -26,7 +26,7 @@ $ cozy-stack feature ratio --context beta '{"set_this_flag": [{"ratio": 0.1, "va
2626

2727
```
2828
--context string The context for the feature flags
29-
-h, --help help for context
29+
-h, --help help for ratio
3030
```
3131

3232
### Options inherited from parent commands

docs/cli/cozy-stack_fixer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cozy-stack fixer <command> [flags]
3131
* [cozy-stack](cozy-stack.md) - cozy-stack is the main command
3232
* [cozy-stack fixer contact-emails](cozy-stack_fixer_contact-emails.md) - Detect and try to fix invalid emails on contacts
3333
* [cozy-stack fixer content-mismatch](cozy-stack_fixer_content-mismatch.md) - Fix the content mismatch differences for 64K issue
34+
* [cozy-stack fixer indexes](cozy-stack_fixer_indexes.md) - Rebuild the CouchDB views and indexes
3435
* [cozy-stack fixer jobs](cozy-stack_fixer_jobs.md) - Take a look at the consistency of the jobs
3536
* [cozy-stack fixer md5](cozy-stack_fixer_md5.md) - Fix missing md5 from contents in the vfs
3637
* [cozy-stack fixer mime](cozy-stack_fixer_mime.md) - Fix the class computed from the mime-type

docs/cli/cozy-stack_fixer_indexes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## cozy-stack fixer indexes
2+
3+
Rebuild the CouchDB views and indexes
4+
5+
### Synopsis
6+
7+
8+
This fixer ensures that the CouchDB views and indexes used by the stack for
9+
this instance are correctly set.
10+
11+
12+
```
13+
cozy-stack fixer indexes <domain> [flags]
14+
```
15+
16+
### Options
17+
18+
```
19+
-h, --help help for indexes
20+
```
21+
22+
### Options inherited from parent commands
23+
24+
```
25+
--admin-host string administration server host (default "localhost")
26+
--admin-port int administration server port (default 6060)
27+
-c, --config string configuration file (default "$HOME/.cozy.yaml")
28+
--host string server host (default "localhost")
29+
-p, --port int server port (default 8080)
30+
```
31+
32+
### SEE ALSO
33+
34+
* [cozy-stack fixer](cozy-stack_fixer.md) - A set of tools to fix issues or migrate content for retro-compatibility.
35+

docs/cli/cozy-stack_serve.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ example), you can use the --appdir flag like this:
6565
--mail-password string mail smtp password
6666
--mail-port int mail smtp port (default 465)
6767
--mail-username string mail smtp username
68+
--mailhog Alias of --mail-disable-tls --mail-port 1025, useful for MailHog
6869
--password-reset-interval string minimal duration between two password reset (default "15m")
6970
--rate-limiting-url string URL for rate-limiting counters, redis or in-memory
7071
--realtime-url string URL for realtime in the browser via webocket, redis or in-memory

model/instance/lifecycle/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func CreateWithoutHooks(opts *Options) (*instance.Instance, error) {
176176
if err := couchdb.CreateNamedDocWithDB(i, settings); err != nil {
177177
return nil, err
178178
}
179-
if err := defineViewsAndIndex(i); err != nil {
179+
if err := DefineViewsAndIndex(i); err != nil {
180180
return nil, err
181181
}
182182
if err := createDefaultFilesTree(i); err != nil {

model/instance/lifecycle/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func GetInstance(domain string) (*instance.Instance, error) {
3333
}
3434

3535
i.Logger().Debugf("Indexes outdated: wanted %d; got %d", couchdb.IndexViewsVersion, i.IndexViewsVersion)
36-
if err = defineViewsAndIndex(i); err != nil {
36+
if err = DefineViewsAndIndex(i); err != nil {
3737
i.Logger().Errorf("Could not re-define indexes and views: %s", err.Error())
3838
return nil, err
3939
}

model/instance/lifecycle/helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func installApp(inst *instance.Instance, slug string) error {
3838
return err
3939
}
4040

41-
func defineViewsAndIndex(inst *instance.Instance) error {
41+
// DefineViewsAndIndex can be used to ensure that the CouchDB views and indexes
42+
// used by the stack are correctly set.
43+
func DefineViewsAndIndex(inst *instance.Instance) error {
4244
if err := couchdb.DefineIndexes(inst, couchdb.Indexes); err != nil {
4345
return err
4446
}

scripts/completion/cozy-stack.bash

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,38 @@ _cozy-stack_fixer_content-mismatch()
16231623
noun_aliases=()
16241624
}
16251625

1626+
_cozy-stack_fixer_indexes()
1627+
{
1628+
last_command="cozy-stack_fixer_indexes"
1629+
1630+
command_aliases=()
1631+
1632+
commands=()
1633+
1634+
flags=()
1635+
two_word_flags=()
1636+
local_nonpersistent_flags=()
1637+
flags_with_completion=()
1638+
flags_completion=()
1639+
1640+
flags+=("--admin-host=")
1641+
two_word_flags+=("--admin-host")
1642+
flags+=("--admin-port=")
1643+
two_word_flags+=("--admin-port")
1644+
flags+=("--config=")
1645+
two_word_flags+=("--config")
1646+
two_word_flags+=("-c")
1647+
flags+=("--host=")
1648+
two_word_flags+=("--host")
1649+
flags+=("--port=")
1650+
two_word_flags+=("--port")
1651+
two_word_flags+=("-p")
1652+
1653+
must_have_one_flag=()
1654+
must_have_one_noun=()
1655+
noun_aliases=()
1656+
}
1657+
16261658
_cozy-stack_fixer_jobs()
16271659
{
16281660
last_command="cozy-stack_fixer_jobs"
@@ -1828,6 +1860,7 @@ _cozy-stack_fixer()
18281860
commands=()
18291861
commands+=("contact-emails")
18301862
commands+=("content-mismatch")
1863+
commands+=("indexes")
18311864
commands+=("jobs")
18321865
commands+=("md5")
18331866
commands+=("mime")
@@ -3268,6 +3301,7 @@ _cozy-stack_serve()
32683301
two_word_flags+=("--mail-port")
32693302
flags+=("--mail-username=")
32703303
two_word_flags+=("--mail-username")
3304+
flags+=("--mailhog")
32713305
flags+=("--password-reset-interval=")
32723306
two_word_flags+=("--password-reset-interval")
32733307
flags+=("--rate-limiting-url=")

scripts/completion/cozy-stack.zsh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ function _cozy-stack_fixer {
689689
commands=(
690690
"contact-emails:Detect and try to fix invalid emails on contacts"
691691
"content-mismatch:Fix the content mismatch differences for 64K issue"
692+
"indexes:Rebuild the CouchDB views and indexes"
692693
"jobs:Take a look at the consistency of the jobs"
693694
"md5:Fix missing md5 from contents in the vfs"
694695
"mime:Fix the class computed from the mime-type"
@@ -707,6 +708,9 @@ function _cozy-stack_fixer {
707708
content-mismatch)
708709
_cozy-stack_fixer_content-mismatch
709710
;;
711+
indexes)
712+
_cozy-stack_fixer_indexes
713+
;;
710714
jobs)
711715
_cozy-stack_fixer_jobs
712716
;;
@@ -747,6 +751,15 @@ function _cozy-stack_fixer_content-mismatch {
747751
'(-p --port)'{-p,--port}'[server port]:'
748752
}
749753

754+
function _cozy-stack_fixer_indexes {
755+
_arguments \
756+
'--admin-host[administration server host]:' \
757+
'--admin-port[administration server port]:' \
758+
'(-c --config)'{-c,--config}'[configuration file (default "$HOME/.cozy.yaml")]:' \
759+
'--host[server host]:' \
760+
'(-p --port)'{-p,--port}'[server port]:'
761+
}
762+
750763
function _cozy-stack_fixer_jobs {
751764
_arguments \
752765
'--admin-host[administration server host]:' \
@@ -1405,6 +1418,7 @@ function _cozy-stack_serve {
14051418
'--mail-password[mail smtp password]:' \
14061419
'--mail-port[mail smtp port]:' \
14071420
'--mail-username[mail smtp username]:' \
1421+
'--mailhog[Alias of --mail-disable-tls --mail-port 1025, useful for MailHog]' \
14081422
'--password-reset-interval[minimal duration between two password reset]:' \
14091423
'--rate-limiting-url[URL for rate-limiting counters, redis or in-memory]:' \
14101424
'--realtime-url[URL for realtime in the browser via webocket, redis or in-memory]:' \

scripts/cozy-app-dev.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ do_start() {
108108
--port "${COZY_STACK_PORT}" \
109109
--admin-port "${COZY_STACK_ADMIN_PORT}" \
110110
--couchdb-url "${COUCHDB_URL}" \
111-
--mail-port 1025 \
112-
--mail-disable-tls \
111+
--mailhog \
113112
--fs-url "file://localhost${vfsdir}" &
114113

115114
wait_for "${COZY_STACK_HOST}:${COZY_STACK_PORT}/version/" "cozy-stack"

tests/integration/lib/stack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def start
3939
end
4040
system("cozy-stack config gen-keys '#{vault}/key'") unless File.exist?("#{vault}/key.enc")
4141
cmd = ["cozy-stack", "serve", "--log-level", "debug",
42-
"--mail-disable-tls", "--mail-port", "1025",
42+
"--mailhog",
4343
"--port", @port, "--admin-port", @admin,
4444
"--fs-url", fsurl,
4545
"--vault-encryptor-key", "#{vault}/key.enc",

web/instances/fixers.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,19 @@ func orphanAccountFixer(c echo.Context) error {
301301
}
302302
}
303303

304-
return c.JSON(http.StatusNoContent, nil)
304+
return c.NoContent(http.StatusNoContent)
305+
}
306+
307+
func indexesFixer(c echo.Context) error {
308+
domain := c.Param("domain")
309+
inst, err := instance.GetFromCouch(domain)
310+
if err != nil {
311+
return err
312+
}
313+
314+
if err := lifecycle.DefineViewsAndIndex(inst); err != nil {
315+
return err
316+
}
317+
318+
return c.NoContent(http.StatusNoContent)
305319
}

web/instances/instances.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,5 @@ func Routes(router *echo.Group) {
488488
// Fixers
489489
router.POST("/:domain/fixers/content-mismatch", contentMismatchFixer)
490490
router.POST("/:domain/fixers/orphan-account", orphanAccountFixer)
491+
router.POST("/:domain/fixers/indexes", indexesFixer)
491492
}

0 commit comments

Comments
 (0)