feat(cli): add nib add + nib ls commands
Default command delegation: `nib "..."` routes to `nib add`. Capture bar parses grammar, creates entities. `nib ls` lists with date grouping, tag filter, 48h default window. Display glyphs for all entity types.
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "nib",
|
||||
Short: "capture and crystallize notes, todos, and events",
|
||||
Args: cobra.ArbitraryArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return cmd.Help()
|
||||
}
|
||||
return runAdd(cmd, args)
|
||||
},
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
if len(os.Args) > 1 {
|
||||
first := os.Args[1]
|
||||
isFlag := strings.HasPrefix(first, "-") && !strings.Contains(first, " ")
|
||||
if first != "help" && first != "completion" &&
|
||||
!isFlag && !isSubcommand(first) {
|
||||
rootCmd.SetArgs(append([]string{"add", "--"}, os.Args[1:]...))
|
||||
}
|
||||
}
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func isSubcommand(name string) bool {
|
||||
for _, c := range rootCmd.Commands() {
|
||||
if c.Name() == name {
|
||||
return true
|
||||
}
|
||||
for _, alias := range c.Aliases {
|
||||
if alias == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(addCmd)
|
||||
rootCmd.AddCommand(lsCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user