Skip to content

Commit

Permalink
Allow 'today' as special keyword for link/unlink
Browse files Browse the repository at this point in the history
The app crashes if no node for the current day has been created, either
from `add` or something else. This allows the user to specify `today` as
a keyword in order to automatically add the date node.
  • Loading branch information
anhnamtran committed Aug 24, 2021
1 parent e5692b7 commit e2efb62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions cmd/grit/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func cmdUncheck(cmd *cli.Cmd) {
func cmdLink(cmd *cli.Cmd) {
cmd.Spec = "ORIGIN TARGETS..."
var (
origin = cmd.StringArg("ORIGIN", "", "origin selector")
origin = cmd.StringArg("ORIGIN", "",
"origin selector. 'today' is a valid option and will" +
" create the node if it doesn't already exist")
targets = cmd.StringsArg("TARGETS", nil, "target selector(s)")
)
cmd.Action = func() {
Expand All @@ -225,6 +227,11 @@ func cmdLink(cmd *cli.Cmd) {
}
defer a.Close()

today := time.Now().Format("2006-01-02")
if *origin == "today" {
*origin = today
}

for _, t := range *targets {
if _, err := a.LinkNodes(*origin, t); err != nil {
errf("Couldn't create link (%s) -> (%s): %v\n", *origin, t, err)
Expand All @@ -236,7 +243,9 @@ func cmdLink(cmd *cli.Cmd) {
func cmdUnlink(cmd *cli.Cmd) {
cmd.Spec = "ORIGIN ( -A | -P | TARGETS... )"
var (
origin = cmd.StringArg("ORIGIN", "", "origin selector")
origin = cmd.StringArg("ORIGIN", "",
"origin selector. 'today' is a valid option and will" +
" create the node if it doesn't already exist")
targets = cmd.StringsArg("TARGETS", nil, "target selector")
allChildren = cmd.BoolOpt("A allChildren", false,
"unlink all children of the node")
Expand All @@ -250,6 +259,11 @@ func cmdUnlink(cmd *cli.Cmd) {
}
defer a.Close()

today := time.Now().Format("2006-01-02")
if *origin == "today" {
*origin = today
}

originNode, err := a.GetGraph(*origin)
if err != nil {
die(err)
Expand Down
2 changes: 1 addition & 1 deletion multitree/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ValidateNodeName(name string) error {
if len(name) == 0 {
return errors.New("invalid node name (empty name)")
}
if len(name) > 100 {
if len(name) > 200 {
return errors.New("invalid node name (name too long)")
}
return nil
Expand Down

0 comments on commit e2efb62

Please sign in to comment.