a6fda5d1ee
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.
53 lines
986 B
Go
53 lines
986 B
Go
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)
|
|
}
|