Skip to content

Commit

Permalink
Allow to skip frontmatter when viewing note (dnote#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungwoncho authored Jan 3, 2021
1 parent e9f3b08 commit a464097
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pkg/cli/cmd/cat/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewCmd(ctx context.DnoteCtx) *cobra.Command {
Aliases: []string{"c"},
Short: "See a note",
Example: example,
RunE: NewRun(ctx),
RunE: NewRun(ctx, false),
PreRunE: preRun,
Deprecated: deprecationWarning,
}
Expand All @@ -64,7 +64,7 @@ func NewCmd(ctx context.DnoteCtx) *cobra.Command {
}

// NewRun returns a new run function
func NewRun(ctx context.DnoteCtx) infra.RunEFunc {
func NewRun(ctx context.DnoteCtx, contentOnly bool) infra.RunEFunc {
return func(cmd *cobra.Command, args []string) error {
var noteRowIDArg string

Expand All @@ -87,7 +87,11 @@ func NewRun(ctx context.DnoteCtx) infra.RunEFunc {
return err
}

output.NoteInfo(info)
if contentOnly {
output.NoteContent(info)
} else {
output.NoteInfo(info)
}

return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/cli/cmd/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var example = `
`

var nameOnly bool
var contentOnly bool

func preRun(cmd *cobra.Command, args []string) error {
if len(args) > 2 {
Expand All @@ -63,6 +64,7 @@ func NewCmd(ctx context.DnoteCtx) *cobra.Command {

f := cmd.Flags()
f.BoolVarP(&nameOnly, "name-only", "", false, "print book names only")
f.BoolVarP(&contentOnly, "content-only", "", false, "print the note content only")

return cmd
}
Expand All @@ -79,13 +81,13 @@ func newRun(ctx context.DnoteCtx) infra.RunEFunc {
}

if utils.IsNumber(args[0]) {
run = cat.NewRun(ctx)
run = cat.NewRun(ctx, contentOnly)
} else {
run = ls.NewRun(ctx, false)
}
} else if len(args) == 2 {
// DEPRECATED: passing book name to view command is deprecated
run = cat.NewRun(ctx)
run = cat.NewRun(ctx, false)
} else {
return errors.New("Incorrect number of arguments")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func NoteInfo(info database.NoteInfo) {
fmt.Printf("\n-------------------------------------------------------\n")
}

func NoteContent(info database.NoteInfo) {
fmt.Printf("%s", info.Content)
}

// BookInfo prints a note information
func BookInfo(info database.BookInfo) {
log.Infof("book name: %s\n", info.Name)
Expand Down

0 comments on commit a464097

Please sign in to comment.