Ver código fonte

doc: Documentation for the short commands.

Serj Kalichev 2 dias atrás
pai
commit
98291f5e21
3 arquivos alterados com 40 adições e 5 exclusões
  1. 17 0
      docs/klish3.en.md
  2. 15 0
      docs/klish3.ru.md
  3. 8 5
      plugins/klish/ptype_command.c

+ 17 - 0
docs/klish3.en.md

@@ -1311,6 +1311,23 @@ All symbols in this section are intended for use in `PTYPE` elements, unless oth
 
 The `COMMAND` symbol checks that the entered argument matches the command name. That is, with the `name` or `value` attributes of the `COMMAND` or `PARAM` elements. If the `value` attribute is set, its value is used as the command name. If not set, the value of the `name` attribute is used. The case of characters in the command name is not taken into account.
 
+Sometimes it’s convenient to have shortcuts for commands so you don’t have to
+type the full names. For example, for a command with the full name
+`environment`, you can define allowed abbreviations, and then entering `env`
+will be enough to invoke it. To define allowed abbreviations, the `value`
+attribute is used (it won’t work with the `name` attribute). In the attribute’s
+value, the mandatory prefix of the command is separated by the `|` symbol from
+the optional part. For example:
+
+```
+<COMMAND name="environment" value="env|ironment" />
+```
+
+For such a command, you can use abbreviations like `env`, `envi`, `envir`, and
+so on. However, strings like `e` and `en` won’t work because they are shorter
+than the minimum required prefix `env`.
+
+
 #### Symbol `completion_COMMAND`
 
 The `completion_COMMAND` symbol is intended for the `COMPL` element nested in `PTYPE`. The symbol is used to form an auto-completion string for a command. The auto-completion for a command is the name of the command itself. If the `value` attribute is set, its value is used as the command name. If not set, the value of the `name` attribute is used.

+ 15 - 0
docs/klish3.ru.md

@@ -2233,6 +2233,21 @@ SEQ сам может быть элементом контейнера SWITCH.
 Если не задан, то используется значение атрибута `name`. Регистр символов в
 названии команды не учитывается.
 
+Иногда удобно иметь сокращения для команд, чтобы не вводить длинные имена
+целиком. Например для команды, имеющей полное имя `environment` можно
+определить допустимые сокращения и тогда для её ввода будет достаточно строки
+`env`. Чтобы определить допустимые сокращения используется атрибут `value`
+(c атрибутом `name` не будет работать). В значении атрибута обязательный
+префикс команды отделяется символом `|` от необязательной части. Например:
+
+```
+<COMMAND name="environment" value="env|ironment" />
+```
+
+Для такой команды можно будет использовать сокращения `env`, `envi`, `envir`,
+и т.д., при этом строки `e` и `en` работать не будут, так как они короче
+минимального префикса `env`.
+
 
 #### Символ `completion_COMMAND`
 

+ 8 - 5
plugins/klish/ptype_command.c

@@ -5,11 +5,14 @@
  * or entry's name.
  *
  * The "value" field supports short variants of commands. That means the user
- * can specify something like this 'value="environment 3"' where "environment" is
- * a full command name and the "3" is minimal prefix length enough for PTYPE to
- * satisfy comparison and return success as return code. I.e. user can type
- * "env", "envi", "envir", ..., "environment" to execute this command. But the
- * strings "e" or "en" is not a case because their length is less than "3".
+ * can specify something like this 'value="env|ironment"' where "environment"
+ * is a full command name and the substring before the "|" is a minimal prefix
+ * enough for PTYPE to satisfy comparison and return success as return code.
+ * I.e. user can type "env", "envi", "envir", ..., "environment" to execute
+ * this command. But the strings "e" or "en" is not a case because their length
+ * is less than minimal prefix. Note the short commands are available only for
+ * the "value" attribute but not for the "name". Because name is a component of
+ * the "path" that allows to address scheme elements.
  *
  * The COMMAND PTYPE uses internal user data attached to the kentry_t structure
  * to store pre-parsed command name with length information. It's necessary to