Skip to content

Commit

Permalink
Fix an issue that stopped the delete command editing files in place
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWright committed Aug 2, 2021
1 parent 40d7022 commit 398f408
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Nothing

## [v1.16.1] - 2021-08-02

### Fixed

- Fixed a bug that stopped the delete command editing files in place.

## [v1.16.0] - 2021-08-01

### Added
Expand Down Expand Up @@ -329,7 +335,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Everything!

[unreleased]: https://github.com/TomWright/dasel/compare/v1.16.0...HEAD
[unreleased]: https://github.com/TomWright/dasel/compare/v1.16.1...HEAD
[v1.16.1]: https://github.com/TomWright/dasel/compare/v1.16.0...v1.16.1
[v1.16.0]: https://github.com/TomWright/dasel/compare/v1.15.0...v1.16.0
[v1.15.0]: https://github.com/TomWright/dasel/compare/v1.14.1...v1.15.0
[v1.14.1]: https://github.com/TomWright/dasel/compare/v1.14.0...v1.14.1
Expand Down
17 changes: 11 additions & 6 deletions internal/command/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type deleteOptions struct {
Multi bool
Compact bool
MergeInputDocuments bool
Out string
}

func runDeleteMultiCommand(cmd *cobra.Command, rootNode *dasel.Node, opts deleteOptions, writeParser storage.WriteParser, writeOptions []storage.ReadWriteOption) error {
Expand All @@ -30,6 +31,7 @@ func runDeleteMultiCommand(cmd *cobra.Command, rootNode *dasel.Node, opts delete
Err: err,
Cmd: cmd,
NullFlag: false,
Out: opts.Out,
})
if err != nil {
return fmt.Errorf("could not delete multiple node: %w", err)
Expand All @@ -42,6 +44,8 @@ func runDeleteMultiCommand(cmd *cobra.Command, rootNode *dasel.Node, opts delete
Node: rootNode,
Parser: writeParser,
Writer: opts.Writer,
File: opts.File,
Out: opts.Out,
}, cmd, writeOptions...); err != nil {
return fmt.Errorf("could not write output: %w", err)
}
Expand Down Expand Up @@ -69,11 +73,7 @@ func runDeleteCommand(opts deleteOptions, cmd *cobra.Command) error {
})
}

if opts.Writer == nil {
opts.Writer = cmd.OutOrStdout()
}

writeParser, err := getWriteParser(readParser, opts.WriteParser, opts.Parser, "-", opts.File)
writeParser, err := getWriteParser(readParser, opts.WriteParser, opts.Parser, opts.Out, opts.File)
if err != nil {
return err
}
Expand All @@ -97,6 +97,7 @@ func runDeleteCommand(opts deleteOptions, cmd *cobra.Command) error {
Err: err,
Cmd: cmd,
NullFlag: false,
Out: opts.Out,
})
if err != nil {
return err
Expand All @@ -109,6 +110,8 @@ func runDeleteCommand(opts deleteOptions, cmd *cobra.Command) error {
Node: rootNode,
Parser: writeParser,
Writer: opts.Writer,
File: opts.File,
Out: opts.Out,
}, cmd, writeOptions...); err != nil {
return fmt.Errorf("could not write output: %w", err)
}
Expand All @@ -117,7 +120,7 @@ func runDeleteCommand(opts deleteOptions, cmd *cobra.Command) error {
}

func deleteCommand() *cobra.Command {
var fileFlag, selectorFlag, parserFlag, readParserFlag, writeParserFlag string
var fileFlag, selectorFlag, parserFlag, readParserFlag, writeParserFlag, outFlag string
var plainFlag, multiFlag, compactFlag, mergeInputDocumentsFlag bool

cmd := &cobra.Command{
Expand All @@ -140,6 +143,7 @@ func deleteCommand() *cobra.Command {
Multi: multiFlag,
Compact: compactFlag,
MergeInputDocuments: mergeInputDocumentsFlag,
Out: outFlag,
}, cmd)
},
}
Expand All @@ -153,6 +157,7 @@ func deleteCommand() *cobra.Command {
cmd.Flags().BoolVarP(&multiFlag, "multiple", "m", false, "Delete multiple results.")
cmd.Flags().BoolVar(&mergeInputDocumentsFlag, "merge-input-documents", false, "Merge multiple input documents into an array.")
cmd.Flags().BoolVarP(&compactFlag, "compact", "c", false, "Compact the output by removing all pretty-printing where possible.")
cmd.Flags().StringVarP(&outFlag, "out", "o", "", "Output destination.")

_ = cmd.MarkFlagFilename("file")

Expand Down

0 comments on commit 398f408

Please sign in to comment.