Skip to content

Commit 6a3b2f9

Browse files
authored
Merge pull request #47 from dparrish/Optargs
Optargs
2 parents 96c4e40 + e65c38c commit 6a3b2f9

File tree

9 files changed

+2354
-582
lines changed

9 files changed

+2354
-582
lines changed

.clang-tidy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
Checks: 'clang-diagnostic-*,clang-analyzer-*'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none
7+
User: dparrish
8+
CheckOptions:
9+
- key: cert-dcl16-c.NewSuffixes
10+
value: 'L;LL;LU;LLU'
11+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
12+
value: '1'
13+
- key: google-readability-braces-around-statements.ShortStatementLines
14+
value: '1'
15+
- key: google-readability-function-size.StatementThreshold
16+
value: '800'
17+
- key: google-readability-namespace-comments.ShortNamespaceLines
18+
value: '10'
19+
- key: google-readability-namespace-comments.SpacesBeforeComments
20+
value: '2'
21+
- key: modernize-loop-convert.MaxCopySize
22+
value: '16'
23+
- key: modernize-loop-convert.MinConfidence
24+
value: reasonable
25+
- key: modernize-loop-convert.NamingStyle
26+
value: CamelCase
27+
- key: modernize-pass-by-value.IncludeStyle
28+
value: llvm
29+
- key: modernize-replace-auto-ptr.IncludeStyle
30+
value: llvm
31+
- key: modernize-use-nullptr.NullMacros
32+
value: 'NULL'
33+
...
34+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.so
44
*.so.*
55
clitest
6+
compile_commands.json

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ DESTDIR =
1010
PREFIX = /usr/local
1111

1212
MAJOR = 1
13-
MINOR = 9
14-
REVISION = 8
13+
MINOR = 10
14+
REVISION = 0
1515
LIB = libcli.so
1616
LIB_STATIC = libcli.a
1717

@@ -79,9 +79,13 @@ install: $(TARGET_LIBS)
7979
rpmprep:
8080
rm -rf libcli-$(MAJOR).$(MINOR).$(REVISION)
8181
mkdir libcli-$(MAJOR).$(MINOR).$(REVISION)
82-
cp -R libcli.{c,h} libcli.spec clitest.c Makefile COPYING README libcli-$(MAJOR).$(MINOR).$(REVISION)
82+
cp -R libcli.{c,h} libcli.spec clitest.c Makefile COPYING README.md doc libcli-$(MAJOR).$(MINOR).$(REVISION)
8383
tar zcvf libcli-$(MAJOR).$(MINOR).$(REVISION).tar.gz --exclude CVS --exclude *.tar.gz libcli-$(MAJOR).$(MINOR).$(REVISION)
8484
rm -rf libcli-$(MAJOR).$(MINOR).$(REVISION)
8585

8686
rpm: rpmprep
8787
rpmbuild -ta libcli-$(MAJOR).$(MINOR).$(REVISION).tar.gz --define "debug_package %{nil}" --clean
88+
89+
lint:
90+
clang-tidy -quiet -warnings-as-errors *.c *.h
91+
Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,111 @@
1-
libcli
1+
Libcli provides a shared C library for including a Cisco-like command-line
2+
interface into other software.
23

3-
libcli emulates a cisco style telnet command-line interface.
4+
It’s a telnet interface which supports command-line editing, history,
5+
authentication and callbacks for a user-definable function tree.
46

57
To compile:
68

7-
make
8-
make install
9+
```sh
10+
$ make
11+
$ make install
12+
```
913

10-
This will install libcli.so into /usr/local/lib. If you want to change
11-
the location, edit Makefile.
14+
This will install `libcli.so` into `/usr/local/lib`. If you want to change the
15+
location, edit Makefile.
1216

13-
There is a test application built called clitest. Run this and telnet
14-
to port 8000.
17+
There is a test application built called clitest. Run this and telnet to port
18+
8000.
1519

1620
By default, a single username and password combination is enabled.
1721

22+
```
1823
Username: fred
1924
Password: nerk
25+
```
2026

21-
Get help by entering "help" or hitting ?.
27+
Get help by entering `help` or hitting `?`.
2228

2329
libcli provides support for using the arrow keys for command-line editing. Up
2430
and Down arrows will cycle through the command history, and Left & Right can be
2531
used for editing the current command line.
32+
2633
libcli also works out the shortest way of entering a command, so if you have a
27-
command "show users grep foobar" defined, you can enter "sh us g foobar" if that
34+
command `show users | grep foobar` defined, you can enter `sh us | g foobar` if that
2835
is the shortest possible way of doing it.
2936

30-
Enter "sh?" at the command line to get a list of commands starting with "sh"
37+
Enter `sh?` at the command line to get a list of commands starting with `sh`
3138

3239
A few commands are defined in every libcli program:
33-
help
34-
quit
35-
exit
36-
logout
37-
history
38-
39-
4040

41+
* `help`
42+
* `quit`
43+
* `exit`
44+
* `logout`
45+
* `history`
4146

4247
Use in your own code:
4348

44-
First of all, make sure you #include <libcli.h> in your C code, and link
45-
with -lcli.
49+
First of all, make sure you `#include <libcli.h>` in your C code, and link with
50+
`-lcli`.
4651

4752
If you have any trouble with this, have a look at clitest.c for a
4853
demonstration.
4954

50-
Start your program off with a cli_init().
55+
Start your program off with a `cli_init()`.
5156
This sets up the internal data structures required.
5257

5358
When a user connects, they are presented with a greeting if one is set using the
54-
cli_set_banner(banner) function.
55-
59+
`cli_set_banner(banner)` function.
5660

5761
By default, the command-line session is not authenticated, which means users
5862
will get full access as soon as they connect. As this may not be always the best
5963
thing, 2 methods of authentication are available.
6064

6165
First, you can add username / password combinations with the
62-
cli_allow_user(username, password) function. When a user connects, they can
66+
`cli_allow_user(username, password)` function. When a user connects, they can
6367
connect with any of these username / password combinations.
6468

65-
Secondly, you can add a callback using the cli_set_auth_callback(callback)
66-
function. This function is passed the username and password as char *, and must
67-
return CLI_OK if the user is to have access and CLI_ERROR if they are not.
69+
Secondly, you can add a callback using the `cli_set_auth_callback(callback)`
70+
function. This function is passed the username and password as `char *`, and must
71+
return `CLI_OK` if the user is to have access and `CLI_ERROR` if they are not.
6872

6973
The library itself will take care of prompting the user for credentials.
7074

71-
72-
73-
7475
Commands are built using a tree-like structure. You define commands with the
75-
cli_register_command(parent, command, callback, privilege, mode, help) function.
76+
`cli_register_command(parent, command, callback, privilege, mode, help)` function.
7677

77-
parent is a cli_command * reference to a previously added command. Using a
78+
`parent` is a `cli_command *` reference to a previously added command. Using a
7879
parent you can build up complex commands.
79-
e.g. to provide commands "show users", "show sessions" and "show people", use
80+
81+
e.g. to provide commands `show users`, `show sessions` and `show people`, use
8082
the following sequence:
8183

84+
```c
8285
cli_command *c = cli_register_command(NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
8386
cli_register_command(c, "sessions", fn_sessions, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the sessions connected");
8487
cli_register_command(c, "users", fn_users, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the users connected");
8588
cli_register_command(c, "people", fn_people, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of the people I like");
89+
```
8690
87-
88-
If callback is NULL, the command can be used as part of a tree, but cannot be
91+
If callback is `NULL`, the command can be used as part of a tree, but cannot be
8992
individually run.
9093
91-
9294
If you decide later that you don't want a command to be run, you can call
93-
cli_unregister_command(command).
95+
`cli_unregister_command(command)`.
9496
You can use this to build dynamic command trees.
9597
96-
9798
It is possible to carry along a user-defined context to all command callbacks
98-
using cli_set_context(cli, context) and cli_get_context(cli) functions.
99+
using `cli_set_context(cli, context)` and `cli_get_context(cli)` functions.
99100
100101
101102
You are responsible for accepting a TCP connection, and for creating a
102103
process or thread to run the cli. Once you are ready to process the
103-
connection, call cli_loop(cli, sock) to interact with the user on the
104+
connection, call `cli_loop(cli, sock)` to interact with the user on the
104105
given socket.
105106
106107
This function will return when the user exits the cli, either by breaking the
107-
connection or entering "quit".
108-
109-
Call cli_done() to free the data structures.
108+
connection or entering `quit`.
110109
110+
Call `cli_done()` to free the data structures.
111111
112-
- David Parrish (david@dparrish.com)

0 commit comments

Comments
 (0)