From 5b623074e009815a12b25d7e6654c32dfab956d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Fri, 17 Dec 2021 18:07:56 +0100 Subject: [PATCH] Take into account `--no-input` with `zk init` (#122) --- CHANGELOG.md | 1 + internal/cli/cmd/init.go | 10 +++++++++- internal/core/notebook_store.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f101299..731170a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. * [#111](https://github.com/mickael-menu/zk/issues/111) Filenames take precedence over folders when matching a sub-path with wiki links. * [#118](https://github.com/mickael-menu/zk/issues/118) Fix infinite loop when parsing a single-character hashtag. +* [#121](https://github.com/mickael-menu/zk/issues/121) Take into account the `--no-input` flag with `zk init`. ## 0.8.0 diff --git a/internal/cli/cmd/init.go b/internal/cli/cmd/init.go index d1d15b6..5dce176 100644 --- a/internal/cli/cmd/init.go +++ b/internal/cli/cmd/init.go @@ -17,7 +17,7 @@ type Init struct { } func (cmd *Init) Run(container *cli.Container) error { - opts, err := startInitWizard() + opts, err := newInitOpts(container) if err != nil { if err == terminal.InterruptErr { return nil @@ -46,6 +46,14 @@ func (cmd *Init) Run(container *cli.Container) error { return nil } +func newInitOpts(container *cli.Container) (core.InitOpts, error) { + if container.Terminal.NoInput { + return core.NewDefaultInitOpts(), nil + } else { + return startInitWizard() + } +} + func startInitWizard() (core.InitOpts, error) { answers := struct { WikiLink bool diff --git a/internal/core/notebook_store.go b/internal/core/notebook_store.go index 134e2ca..8002772 100644 --- a/internal/core/notebook_store.go +++ b/internal/core/notebook_store.go @@ -102,6 +102,16 @@ type InitOpts struct { MultiwordTags bool } +// NewDefaultInitOpts creates a new instance of InitOpts with the default values. +func NewDefaultInitOpts() InitOpts { + return InitOpts{ + WikiLinks: true, + Hashtags: true, + ColonTags: false, + MultiwordTags: false, + } +} + // Init creates a new notebook at the given file path. func (ns *NotebookStore) Init(path string, options InitOpts) (*Notebook, error) { wrap := errors.Wrapper("init")