Browse Source

Allow to use edit command without argument

Leo 9 years ago
parent
commit
bf03447f78
2 changed files with 9 additions and 4 deletions
  1. 1 0
      CHANGELOG.md
  2. 8 4
      src/command_def.ml

+ 1 - 0
CHANGELOG.md

@@ -14,6 +14,7 @@
    command or the next one. The problem is that you can't call it with an
    option. To do this, use the `run` subcommand.
  + Improve list subcommand, now using Textutils library, displaying in an array
+ + Improve editing command (explain how to use to add commands, improve messages…)
  + Code clean up
  + Add unit tests
  + Add licence warning

+ 8 - 4
src/command_def.ml

@@ -182,14 +182,18 @@ let state =
 let edit =
   basic
     ~summary:"Edit the [COMMAND_NUMBER]th command of the rc file in your \
-    $EDITOR. May be used to add new entries."
+    $EDITOR. May be used to add new entries, without argument, one new \
+    command per line."
     Spec.(
       empty
       +> shared_params
-      +> anon ("command_number" %: int)
+      +> anon (maybe ("command_number" %: int))
     )
-    (fun { rc } default_n () ->
-      Edit_command.run ~rc default_n)
+    (fun { rc } n () ->
+      let position = Option.value
+        ~default:(List.length (rc.Settings_t.progs) - 1) n
+      in
+      Edit_command.run ~rc position)
 ;;
 
 (* To display informations about the licence *)