Skip to content

Commit

Permalink
Take into account --no-input with zk init (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Dec 17, 2021
1 parent e317f0d commit 5b62307
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion internal/cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/core/notebook_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5b62307

Please sign in to comment.