Skip to content

Commit e2efb62

Browse files
committed
Allow 'today' as special keyword for link/unlink
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.
1 parent e5692b7 commit e2efb62

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cmd/grit/cmds.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ func cmdUncheck(cmd *cli.Cmd) {
215215
func cmdLink(cmd *cli.Cmd) {
216216
cmd.Spec = "ORIGIN TARGETS..."
217217
var (
218-
origin = cmd.StringArg("ORIGIN", "", "origin selector")
218+
origin = cmd.StringArg("ORIGIN", "",
219+
"origin selector. 'today' is a valid option and will" +
220+
" create the node if it doesn't already exist")
219221
targets = cmd.StringsArg("TARGETS", nil, "target selector(s)")
220222
)
221223
cmd.Action = func() {
@@ -225,6 +227,11 @@ func cmdLink(cmd *cli.Cmd) {
225227
}
226228
defer a.Close()
227229

230+
today := time.Now().Format("2006-01-02")
231+
if *origin == "today" {
232+
*origin = today
233+
}
234+
228235
for _, t := range *targets {
229236
if _, err := a.LinkNodes(*origin, t); err != nil {
230237
errf("Couldn't create link (%s) -> (%s): %v\n", *origin, t, err)
@@ -236,7 +243,9 @@ func cmdLink(cmd *cli.Cmd) {
236243
func cmdUnlink(cmd *cli.Cmd) {
237244
cmd.Spec = "ORIGIN ( -A | -P | TARGETS... )"
238245
var (
239-
origin = cmd.StringArg("ORIGIN", "", "origin selector")
246+
origin = cmd.StringArg("ORIGIN", "",
247+
"origin selector. 'today' is a valid option and will" +
248+
" create the node if it doesn't already exist")
240249
targets = cmd.StringsArg("TARGETS", nil, "target selector")
241250
allChildren = cmd.BoolOpt("A allChildren", false,
242251
"unlink all children of the node")
@@ -250,6 +259,11 @@ func cmdUnlink(cmd *cli.Cmd) {
250259
}
251260
defer a.Close()
252261

262+
today := time.Now().Format("2006-01-02")
263+
if *origin == "today" {
264+
*origin = today
265+
}
266+
253267
originNode, err := a.GetGraph(*origin)
254268
if err != nil {
255269
die(err)

multitree/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func ValidateNodeName(name string) error {
1313
if len(name) == 0 {
1414
return errors.New("invalid node name (empty name)")
1515
}
16-
if len(name) > 100 {
16+
if len(name) > 200 {
1717
return errors.New("invalid node name (name too long)")
1818
}
1919
return nil

0 commit comments

Comments
 (0)