Skip to content

Commit 3f1ab6b

Browse files
committed
Updated documentation and Makefiles
1 parent 952180a commit 3f1ab6b

File tree

11 files changed

+114
-27
lines changed

11 files changed

+114
-27
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
tests/regressiontests/test-standalone.sh
66
tests/regressiontests/test.sh
7+
8+
doc/_build

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ New features:
66
* Support for positional args with default values.
77
* "Intelligent" shell auto-quoting of macro arguments.
88
* Improvement of standalone parsing code mode.
9+

doc/Makefile.pieces

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ DOCDIR ?= .
22
RESOURCES ?= ../resources
33

44
MINIMAL = $(RESOURCES)/examples/minimal.sh
5+
STATICDIR = _static
56

67
NUL =
78

89
PIECES = \
9-
minimal-output-help.txt \
10-
minimal-output-foobar.txt \
11-
minimal-output-noverbose.txt \
10+
$(STATICDIR)/minimal-output-help.txt \
11+
$(STATICDIR)/minimal-output-foobar.txt \
12+
$(STATICDIR)/minimal-output-noverbose.txt \
1213
$(NUL)
1314

1415
pieces: $(PIECES)
@@ -21,15 +22,15 @@ define CMD_OUT
2122
$< $(FLAGS) | sed -e 's/^/ /' >> $@
2223
endef
2324

24-
minimal-output-help.txt: $(MINIMAL)
25+
$(STATICDIR)/minimal-output-help.txt: $(MINIMAL)
2526
$(eval FLAGS := -h)
2627
$(CMD_OUT)
2728

28-
minimal-output-foobar.txt: $(MINIMAL)
29+
$(STATICDIR)/minimal-output-foobar.txt: $(MINIMAL)
2930
$(eval FLAGS := foo -o bar --verbose)
3031
$(CMD_OUT)
3132

32-
minimal-output-noverbose.txt: $(MINIMAL)
33+
$(STATICDIR)/minimal-output-noverbose.txt: $(MINIMAL)
3334
$(eval FLAGS := foo -o bar)
3435
$(CMD_OUT)
3536

doc/_static/minimal-output-foobar.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
::
2+
3+
../resources/examples/minimal.sh foo -o bar --verbose
4+
5+
Positional arg value: foo
6+
Optional arg --option value: bar

doc/_static/minimal-output-help.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
::
2+
3+
../resources/examples/minimal.sh -h
4+
5+
This is a minimal demo of Argbash potential
6+
Usage: ../resources/examples/minimal.sh <positional-arg> [--option <arg>] [--(no-)verbose] [--version] [--help]
7+
<positional-arg>: Positional arg
8+
-o,--option: A option with short and long flags and default (default: 'b')
9+
--verbose,--no-verbose: A boolean option with long flag (and implicit default: off) (default: 'off')
10+
-v,--version: Prints version
11+
-h,--help: Prints help
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
::
2+
3+
../resources/examples/minimal.sh foo -o bar
4+
5+
Not telling anything, verbose mode is off

doc/example.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ Here, we can notice multiple notable things:
1818

1919
So let's try the script in action! Let's see what happens when we pass the -h option:
2020

21-
.. include:: minimal-output-help.txt
21+
.. include:: _static/minimal-output-help.txt
2222

2323
OK, so it seems that passing it one (mandatory) positional arg will do the trick:
2424

25-
.. include:: minimal-output-noverbose.txt
25+
.. include:: _static/minimal-output-noverbose.txt
2626

2727
Oops, we have forgot to turn verbose output on! Let's fix that...
2828

29-
.. include:: minimal-output-foobar.txt
29+
.. include:: _static/minimal-output-foobar.txt
3030

3131
Closer look
3232
-----------

doc/index.rst

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Argbash documentation
22
=====================
33

4+
Argbash
5+
-------
6+
7+
``Argbash`` (`<https://github.com/matejak/argbash>`_) is a ``Bash`` code generator that can assist you in writing scripts that accept arguments.
8+
You declare arguments that your script should use in few lines and then, you run ``Argbash`` on those declarations to get a parsing code that can be used on all platforms that have ``Bash`` (Linux, OSX, MS Windows, ...).
9+
``Argbash`` is free software, you are free to use it, share it, modify it and share the modifications with the world, since it is published under the 3-clause BSD linense.
10+
11+
:Authors:
12+
- `Matěj Týč <https://github.com/matejak>`_
13+
14+
:Copyright:
15+
- 2014-2015, Matěj Týč
16+
417
Quickstart
518
----------
619

@@ -16,27 +29,55 @@ You need:
1629
* ``bash>=3.0``
1730
* ``autoconf>=2.64`` (Argbash makes use of the ``autom4te`` utility)
1831

19-
2032
Writing a template
2133
++++++++++++++++++
2234

2335
Let's stick with a testing script that accepts some arguments and then it just prints them out.
2436
So, let's say that we would like a script that produces the following help message:
2537

38+
.. literalinclude:: _static/minimal-output-help.txt
39+
:start-after: minimal.sh
40+
41+
Then, it means that we need following arguments
2642

27-
Then, it means that we need arguments:
43+
* One mandatory positional argument.
44+
(In other words, an argument that must be passed and that is not preceeded by options such as ``--foo``, ``-f``.)
45+
* Four optional arguments:
2846

29-
*
47+
* ``--option`` that accepts one value,
48+
* ``--verbose`` that doesn't accept any value --- it either is or isn't specified,
49+
* ``--version`` that also doesn't accept any value and the program is supposed just to print its version and quit afterwards, and finally
50+
* ``--help`` that prints a help message and also quits.
3051

3152
Therefore, we write this to the template:
3253

54+
.. literalinclude:: ../resources/examples/minimal.m4
55+
:language: bash
56+
:end-before: needed because of Argbash
57+
3358
The body of the script is trivial, but note that it is enclosed in square brackets.
3459
They are "hidden" in comments, but still, they have to be there.
3560

61+
.. literalinclude:: ../resources/examples/minimal.m4
62+
:language: bash
63+
:start-after: ARGBASH_GO
3664

3765
We generate the script from the template:
3866

39-
The output is good!
67+
::
68+
69+
bin/argbash.sh script.m4 -o script.sh
70+
71+
72+
Now we launch it and the output is good!
73+
74+
::
75+
76+
./script.sh posi-tional -o opt-ional --verbose
77+
78+
Positional arg value: posi-tional
79+
Optional arg --option value: opt-ional
80+
4081

4182
Limitations
4283
+++++++++++
@@ -48,9 +89,9 @@ Limitations
4889
#. The delimiter between optional argument name and value is whitespace, ``=`` is not supported.
4990
Create an issue if this disturbs you, it should be quite easy to implement.
5091
#. Clustering of short arguments (e.g. using ``-xzf`` instead of ``-x -z -f``) is not supported.
51-
#. The square brackets in your script have to match (i.e. every opening square bracket ``[`` should be followed at some point by a closing square bracket ``]``)
52-
This limitation does not apply if you have the argument parsing code in a separate file.
53-
92+
#. The square brackets in your script should match (i.e. every opening square bracket ``[`` should be followed at some point by a closing square bracket ``]``).
93+
More precisely, the number of closing square brackets ``]`` must not exceed the number of opening ``[``.
94+
This limitation does apply to files that are processed by ``argbash.sh`` --- you are fine if you have the argument parsing code in a separate file and you don't use the ``INCLUDE_PARSING_CODE``.
5495

5596
Index
5697
-----

resources/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bootstrap:
4949
examples: $(EXAMPLES)
5050

5151
check: unittests regressiontests
52+
$(MAKE) tests-clean
5253

5354
unittests:
5455
autom4te -l m4sugar -I ../src/ ../tests/unittests/list.m4

resources/packages/Makefile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
VERSION = $(shell cat ../../src/version)
22

3-
SOURCE = argbash-$(VERSION).tar.gz
3+
SOURCE = build/argbash-$(VERSION).tar.gz
44

5-
LICENSE: ../../LICENSE
5+
build/LICENSE: ../../LICENSE | build
66
cp $< $@
77

8-
md5-LICENSE: LICENSE
8+
build/md5-LICENSE: build/LICENSE | build
99
md5sum $< | cut -f 1 -d ' ' > $@
1010

1111
source: $(SOURCE)
1212

13-
$(SOURCE):
13+
$(SOURCE): | build
1414
wget -O $@ https://github.com/matejak/argbash/archive/$(VERSION).tar.gz
1515

16-
md5-$(VERSION): $(SOURCE)
16+
build/md5-$(VERSION): $(SOURCE)
1717
md5sum $< | cut -f 1 -d ' ' > $@
1818

1919
define substitute =
@@ -23,16 +23,22 @@ cat $< \
2323
| sed -e 's/@PKGREL@/$(PKGREL)/' \
2424
| sed -e 's/@DESC@/Bash argument parsing code generator/' \
2525
| sed -e 's|@URL@|https://github.com/matejak/argbash|' \
26-
| sed -e 's/@MD5SUM@/$(shell cat md5-$(VERSION))/' \
27-
| sed -e 's/@LIC_MD5UM@/$(shell cat md5-LICENSE)/' \
26+
| sed -e 's/@MD5SUM@/$(shell cat $(word 3,$+))/' \
27+
| sed -e 's/@LIC_MD5UM@/$(shell cat $(word 4,$+))/' \
2828
> $@
2929
endef
3030

31-
PKGBUILD: arch/PKGBUILD $(SOURCE) md5-$(VERSION) md5-LICENSE
31+
build:
32+
mkdir $@
33+
34+
build/PKGBUILD: arch/PKGBUILD $(SOURCE) build/md5-$(VERSION) build/md5-LICENSE
3235
$(substitute)
3336

34-
archlinux: PKGBUILD
35-
makepkg -f
37+
archlinux: build/PKGBUILD
38+
cd build && makepkg -f
3639

37-
SPEC: rpm/SPEC $(SOURCE)
40+
build/SPEC: rpm/SPEC $(SOURCE)
3841
$(substitute)
42+
43+
clean:
44+
$(RM) build/*

tests/regressiontests/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ TESTS = \
99
args-salone \
1010
$(NUL)
1111

12+
# test-salone is side-effect of call-salone
13+
SCRIPTS = \
14+
$(TESTDIR)/test.sh \
15+
$(TESTDIR)/test2.sh \
16+
$(TESTDIR)/test-standalone.sh \
17+
$(TESTDIR)/test-standalone2.sh \
18+
$(TESTDIR)/call-salone.sh \
19+
$(TESTDIR)/test-salone.sh \
20+
$(NUL)
21+
1222
regressiontests: $(TESTS)
1323

1424
stability: $(TESTDIR)/test.sh $(TESTDIR)/test2.sh
@@ -39,3 +49,6 @@ args-salone: $(TESTDIR)/call-salone.sh
3949

4050
stability-salone: $(TESTDIR)/test-standalone.sh $(TESTDIR)/test-standalone2.sh
4151
diff -q $< $(word 2,$^)
52+
53+
tests-clean:
54+
$(RM) $(SCRIPTS)

0 commit comments

Comments
 (0)