Skip to content

Commit 7b08eb2

Browse files
committed
Fixed documentation
1 parent fa09fe4 commit 7b08eb2

8 files changed

+241
-304
lines changed

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ GEM
4545
tilt
4646
htmlcompressor (0.0.6)
4747
yui-compressor (~> 0.9.6)
48+
json (1.7.7)
4849
kramdown (1.0.2)
4950
less (2.3.2)
5051
commonjs (~> 0.2.6)
@@ -91,6 +92,7 @@ DEPENDENCIES
9192
coffee-script (~> 2.2.0)
9293
cssminify (~> 1.0.2)
9394
htmlcompressor (~> 0.0.3)
95+
json (~> 1.7.7)
9496
kramdown (~> 1.0.1)
9597
less (~> 2.3.2)
9698
listen (= 1.3.1)

docs/aeshconsole.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: docs
33
title: High Level API
4-
index: 2
4+
index: 3
55
---
66

77
High Level API

docs/alias.adoc

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
---
22
layout: docs
33
title: Aliases
4-
index: 9
4+
index: 8
55
---
66

77
Aliases
8-
-------
8+
=======
9+
Ståle W. Pedersen
10+
:Author: Ståle W. Pedersen
11+
12+
:source-highlighter: prettify
13+
14+
== Aliases
915
1016
Aesh provide alias functionality similar to Bash alias.
1117
1218
For those that do not know what aliases is, it allows a string to be substituted for a word when it is used as the first word of a simple command. Aesh maintains a list of aliases that may be set and unset with the +alias+ and +unalias+ commands.
1319
1420
Aesh always read a complete line of input before executing. Aliases are expanded when a command is read.
1521
16-
Set/Unset Aliases
17-
~~~~~~~~~~~~~~~~~
22+
=== Set/Unset Aliases
1823
1924
Aliases are created with the +alias+ command either in the shell or specified in a file thats read when aesh starts. This file can be set in the +Settings+ class. The format to define aliases is: +alias aliasname='command -params'+. This is identical in a shell and file.
2025
2126
To remove an existing alias specify the name of the alias after the +unalias+ command. eg: +unalias aliasname+.
2227
23-
Alias persistence
24-
~~~~~~~~~~~~~~~~~
28+
=== Alias persistence
2529
2630
By default aliases are enabled and must be turned off via the +Settings+ object. It will also try to read aliases from a the specified file and write to the file during shutdown. This can also be disabled if wanted.

docs/command.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Ståle W. Pedersen
1313
1414
== Command
1515
16-
A command in Æsh is a _program_ thats executed in a shell/terminal.
16+
A command in Æsh is a _program_ thats executed in a shell/terminal.
1717
1818
To define a command you have to implement the https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/console/command/Command.java[Command] interface. This interface have one method, execute, which is called when the command is executed.
1919

docs/console.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: docs
33
title: Low level API
4-
index: 2
4+
index: 4
55
---
66

77
Low level API

docs/editingmode.adoc

+16-19
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,32 @@ index: 7
55
---
66

77
Editing
8-
-------
8+
=======
9+
Ståle W. Pedersen
10+
:Author: Ståle W. Pedersen
11+
12+
:source-highlighter: prettify
13+
14+
== Editing
915
1016
Similar to the GNU Readline library Æsh provides functions that allow users to edit command lines as they are typed in. Æsh har two different editing modes, Emacs and Vi. As with GNU Readline Emacs mode is default.
1117
Features in Æsh includes functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous commands.
1218
13-
Introduction to Line Editing
14-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
=== Introduction to Line Editing
1520
1621
Often during an interactive session you type in a long line of text, only to notice that the first word on the line is misspelled. Æsh gives you a set of commands for manipulating the text as you type it in, allowing you to just fix your typo, and not forcing you to retype the majority of the line. Using these editing commands, you move the cursor to the place that needs correction, and delete or insert the text of the corrections. Then, when you are satisfied with the line, you simply press +RET+. You do not have to be at the end of the line to press +RET+; the entire line is accepted regardless of the location of the cursor within the line.
1722
1823
To describe the notation used to represent keystrokes, the text +C-k+ is read as 'Control-K' describes the character produced when the +k+ key is pressed while the Control key is depressed. The text +M-k+ is read as 'Meta-K' and describes the character produced when the Meta key (if you have one) is pressed, and the +k+ key is pressed. The Meta key is labeled +ALT+ on many keyboards.
1924
20-
Essentials
21-
~~~~~~~~~~
25+
=== Essentials
2226
2327
In order to enter characters into the line, simply type them. The typed character appears where the cursor was, and then the cursor moves one space to the right. If you mistype a character, you can use your erase character to back up and delete the mistyped character.
2428
2529
Sometimes you may mistype a character, and not notice the error until you have typed several other characters. In that case, you can type +C-b+ to move the cursor to the left, and then correct your mistake. Afterwards, you can move the cursor to the right with +C-f+.
2630
2731
When you add text in the middle of a line, you will notice that characters to the right of the cursor are `pushed over' to make room for the text that you have inserted. Likewise, when you delete text behind the cursor, characters to the right of the cursor are `pulled back' to fill in the blank space created by the removal of the text. A list of the bare essentials for editing the text of an input line follows.
2832
29-
Emacs Commands
30-
~~~~~~~~~~~~~~
33+
=== Emacs Commands
3134
3235
* +C-b+
3336
** Move back one character.
@@ -58,39 +61,34 @@ empty line.
5861
** Kill from the cursor to the end of the current word, or, if between words, to the end of the next word.
5962
Word boundaries are the same as those used by +M-f+.
6063
61-
Vi Commands
62-
~~~~~~~~~~~
64+
=== Vi Commands
6365
6466
Æsh does not have a full set of +vi+ editing functions, it does contain enough to allow simple editing of the line. Æsh vi mode behaves as specified in the POSIX standard.
6567
6668
When you enter a line in +vi+ mode, you are already placed in 'insertion' mode, as if you had typed an +'i'+. Pressing +ESC+ switches you into `command' mode, where you can edit the text of the line with the standard +vi+ movement keys, move to previous history lines with +'k'+ and subsequent lines with +'j'+, and so forth.
6769
6870
In order to switch interactively between +emacs+ and +vi+ editing modes, use the command +M-C-j+ (bound to emacs-editing-mode when in +vi+ mode and to vi-editing-mode in +emacs+ mode). The Readline default is +emacs+ mode.
6971
70-
Searching for Commands in History
71-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
=== Searching for Commands in History
7273
7374
Æsh provides commands for searching through the command history for lines containing a specified string. There are two search modes: *incremental* and *non-incremental*.
7475
7576
Incremental searches begin before the user has finished typing the search string. As each character of the search string is typed, Æsh displays the next entry from the history matching the string typed so far. An incremental search requires only as many characters as needed to find the desired history entry.
7677
To search backward in the history for a particular string, type +C-r+. Typing +C-s+ searches forward through the history. The characters present in the value of the +isearch-terminators+ variable are used to
7778
terminate an incremental search. If that variable has not been assigned a value, the +ESC+ and +C-J+ characters will terminate an incremental search. +C-g+ will abort an incremental search and restore the original line. When the search is terminated, the history entry containing the search string becomes the current line.
7879
79-
Æsh Init File
80-
~~~~~~~~~~~~~
80+
=== Æsh Init File
8181
8282
Although the Æsh library comes with a set of Emacs-like keybindings installed by default, it is possible to use a different set of keybindings.
8383
Any user can customize programs that use Readline by putting commands in an +inputrc+ file, conventionally in his home directory. The name of this file is taken from the value of the environment variable +INPUTRC+. If that variable is unset, the default is +~/.inputrc+. If that file does not exist or cannot be read, the ultimate default is +/etc/inputrc+.
8484
8585
It is also possible to change from the default Emacs-like key binding to use Vi line editing in the init file.
8686
87-
Æsh Init File Syntax
88-
~~~~~~~~~~~~~~~~~~~~
87+
=== Æsh Init File Syntax
8988
9089
Æsh only support a simple structure of the GNU Readline init file. The current implementation only support variable settings and key bindings outside of conditional constructs. Blank lines are ignored and lines beginning with a +#+ are comments.
9190
92-
Variables
93-
~~~~~~~~~
91+
=== Variables
9492
9593
The syntax for setting variables is simple: +set variable value+
9694
@@ -105,8 +103,7 @@ Current supported variable settings in Æsh:
105103
* +disable-completion+
106104
** If set to +On+, Readline will inhibit word completion. Completion characters will be inserted into the line as if they had been mapped to +self-insert+. The default is +off+.
107105
108-
Key Bindings
109-
~~~~~~~~~~~~
106+
=== Key Bindings
110107
111108
The syntax for controlling key bindings in the init file is simple. First you need to find the name of the command that you want to change. The following sections contain tables of the command name, the default keybinding, if any, and a short description of what the command does.
112109
Once you know the name of the command, simply place on a line in the init file the name of the key you wish to bind the command to, a colon, and then the name of the command. There can be no space between the key name and the colon -- that will be interpreted as part of the key name. The name of the key can be expressed in different ways, depending on what you find most comfortable.

docs/parser.adoc

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
layout: docs
3+
title: Command Line Parser
4+
index: 9
5+
---
6+
7+
Parse
8+
=====
9+
Ståle W. Pedersen
10+
:Author: Ståle W. Pedersen
11+
12+
:source-highlighter: prettify
13+
14+
== Parse
15+
16+
=== Command Line Parser
17+
18+
Æsh provide a Command Line Parser API which make it very easy to parse command lines. The command line parser is independant of the Console API, but can be used with it if wanted. The API support defining the commands you want parsed both with annotations and with a builder pattern.
19+
20+
=== Annotations
21+
22+
Probably the easiest way to define a parser is by using annotations.
23+
The annotation must be defined at class level and is called link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/CommandDefinition.java[CommandDefinition].
24+
CommandDefinition is the only strong requirement, but without any Options or Arguments the command would not accept any attributes.
25+
26+
There are four different option types:
27+
28+
link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/Option.java[*Option*]
29+
is the simplest kind of Option with only one value
30+
31+
Example: -h foo
32+
33+
link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/OptionList.java[OptionList]
34+
can contain several values. It must be defined in connection to a field that implements Collection.
35+
36+
Example: --foo bar1,bar2,bar3
37+
38+
link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/OptionGroup.java[OptionGroup]
39+
is similar to OptionList in that it store several values, but OptionGroup also store the key given. This annotation must be used in connection to a field that implements Map.
40+
41+
Example: -Dname1=value1 -Dname2=value2
42+
43+
link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/Arguments.java[Arguments]
44+
defines the possible arguments thats given to a command. It do not require any option key, but as OptionList it require that the field must implement Collection.
45+
46+
=== A simple first example:
47+
[source,java]
48+
.Example1.java
49+
----
50+
@CommandDefinition(name = "example1", description = "a simple example")
51+
public class Example1 {
52+
53+
@Option(name = "X", description = "enable X", hasValue = false)
54+
private Boolean enableX;
55+
56+
@Option(shortName = 'e', name = "equal", description = "enable equal", required = true)
57+
private String equal;
58+
59+
@Option(shortName = 'i', name = "int1")
60+
private Integer int1;
61+
62+
@OptionList
63+
public List<String> values;
64+
65+
public Boolean getEnableX() { return enableX; }
66+
public String getEqual() { return equal; }
67+
public List<String> getValues() { return values; }
68+
}
69+
----
70+
So lets make it a bit more interesting and say that we want to use this class to parse an line like:
71+
"example1 --X --equal blabla --values one,two,three"
72+
[source,java]
73+
.Example1Test.java
74+
----
75+
Example1 example1 = new Example1();
76+
//this will throw an error if the object do not use the required annotations and
77+
//if the line contain option name/values that do not match the defined options
78+
ParserGenerator.parseAndPopulate(example1, "example1 --X --equal blabla --values one,two,three");
79+
assertTrue(example1.getEnableX());
80+
assertEquals("blabla", example1.getEqual());
81+
assertEquals("one", example1.getValues().get(0));
82+
----
83+
A lot of the different settings are available for each option type which are described below.
84+
85+
=== Option
86+
87+
The different Option types have some common elements like:
88+
89+
* +name+
90+
** The option name. If it's not set the field name will be used. Two dashes (--) are added to the name on the command line.
91+
* +shortName+
92+
** The short option name. If it's not set the first char of name will be used. One dash (-) is added to the short name on the command line.
93+
* +description+
94+
** A simple description of the option. This info is displayed when help info is shown.
95+
* +required+
96+
** Specify if this option is required. Defaults to false.
97+
* +defaultValue[]+
98+
** Specify the default value(s) that will be used if the option do not have any value. Defaults to empty array.
99+
* +hasValue+
100+
** Define if this option should have a value connected to it. Only possible to set this to true when the field type is Boolean/boolean. Default is true.
101+
* +converter+
102+
** Specify a custom converter for the data type of the connected field.
103+
* +completer+
104+
** Specify a custom completer
105+
* +validator+
106+
** Specify a custom validator
107+
108+
=== Converter
109+
When using a "custom" type for a field a converter is needed to inject the correct value. To ensure this we created a simple interface that all the converter implementations need to implement:
110+
[source,java]
111+
.CLConverter.java
112+
----
113+
public interface CLConverter<T> {
114+
T convert(String input);
115+
}
116+
----
117+
118+
Lets show an example of a rather simple (and ignorant) CurrencyConverter:
119+
[source, java]
120+
.CurrencyConverter.java
121+
----
122+
import java.util.Currency;
123+
124+
public class CurrencyConverter implements CLConverter<Currency> {
125+
@Override
126+
public Currency convert(String input) {
127+
return Currency.getInstance(input);
128+
}
129+
}
130+
----
131+
A more production friendly converter would try to do some validation of the input etc...
132+
133+
=== Completer
134+
Note that a completer is not needed if you only want to parse a command line and just populate the values. But if you are creating your own commands and want the possibility to autocomplete the values you need a completer.
135+
Aesh already have a built in completer for Files and Boolean/booleans, all other types require adefined completer.
136+
The Completer interface looks like:
137+
[source, java]
138+
.OptionCompleter.java
139+
----
140+
public interface OptionCompleter {
141+
CompleterData complete(String completeValue);
142+
}
143+
----
144+
145+
A FooCompleter
146+
[source, java]
147+
.FooOptionCompleter.java
148+
----
149+
public class FooOptionCompleter {
150+
@Override
151+
public CompleterData complete(String completeValue) {
152+
List<String> values = new ArrayList<String>();
153+
if(completeValue == null || completeValue.length() == 0)
154+
values.add("Foo");
155+
else if("Foo".startsWith(completeValue))
156+
values.add("Foo")
157+
return new CompleterData(values);
158+
}
159+
}
160+
----
161+
162+
=== Validator
163+
The validator is optional and will be executed during population of the option value. The validator interface looks like:
164+
[source,java]
165+
.OptionValidator.java
166+
----
167+
public interface OptionValidator<T> {
168+
void validate(T value) throws OptionValidatorException;
169+
}
170+
----
171+
172+
Note that implementations of this interface must have an empty constructor.
173+
174+
=== Builder
175+
176+
It is also possible to create a parser by using the builder classes. As with annotations there are two classes; link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/ParserBuilder.java[ParserBuilder] and link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/OptionBuilder.java[OptionBuilder].
177+
A simple example on how they can be used:
178+
179+
How the parser is used is described in the section below.
180+
181+
=== Usage
182+
183+
When using annotations you create the parser like:
184+
185+
[source,java]
186+
----
187+
CommandLineParser parser = ParserGenerator.generateParser(MyCommand1.class);
188+
----
189+
190+
With a builder you use:
191+
[source,java]
192+
----
193+
CommandLineParser parser = ParserBuilder(....).generateParser();
194+
----
195+
196+
The link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/CommandLineParser.java[CommandLineParser] object has two tasks. First is to parse a command line and the other is to print out usage info based on the defined parameter and options.
197+
198+
To parse a line simply do:
199+
200+
[source,java]
201+
----
202+
CommandLine cl = commandLineParser.parse(inputString);
203+
----
204+
205+
The link:https://github.com/aeshell/aesh/blob/master/src/main/java/org/jboss/aesh/cl/CommandLine.java[CommandLine] class have many defined methods of checking if specific options where enabled and with what value.
206+
207+
Please note that if any unspecified options are found an IllegalArgumentException will be thrown. Also, if a required option is not found or options specified with a value, but is not given any an IllegalArgumentException will be thrown.
208+
209+
The CommandLine also feature a nice way of printing out a usage text (help info). This text is parsed from the defined parameter/options.
210+

0 commit comments

Comments
 (0)