-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.cpp
84 lines (67 loc) · 1.83 KB
/
help.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* This file is part of Tcl One-Liner (tol).
* See tol.h for the COPYRIGHT notice.
*/
#include <iostream>
#include "tol.h"
void
Tol::PrintVersion() const
{
std::cout << "tol version " TOL_VERS " (" TOL_TIME ")" << std::endl;
}
void
Tol::PrintUsage() const
{
PrintVersion();
std::cout << R"(
Copyright (C) 2014 Pietro Cerutti <gahr@gahr.ch>
Redistribution and use in source and binary forms, with or without
modification, are permitted under the 2-clause BSD License.
Usage: tol ?arg ...?
arg Evaluate the Tcl command inside 'arg'.
-a Accumulate arguments and evaluate them only at the end.
-c Evaluate the following argument if it is a complete
Tcl command, or concatenate subsequent arguments up
to the first one not preceeded by -c until they form
a complete Tcl command.
-e Display some examples of usage
-i Ignore any errors from the following argument.
-p Print the result of the command in the following argument.
-r Reset the interpreter.
-s var val Assign the value 'val' to the variable 'var'.
-h, -v Display this message.
)";
}
void
Tol::PrintExamples() const
{
PrintVersion();
std::cout << R"(
Examples:
tol 'puts Hello'
>> Hello
tol -p 'expr {1+2}'
>> 3
tol 'set a 2' 'puts $a'
>> 2
tol 'set a 2' -r 'puts $a'
>> can't read "a": no such variable
>> while executing
>> "puts $a"
tol 'puts before' 'set a 2' -r -i 'puts $a' 'puts after'
>> before
>> after
tol -s home $HOME 'puts "we are living in $home"'
>> we are living in /Users/gahr
tol -c 'set vars [dict create' \
-c editor -c $EDITOR \
-c pager -c $PAGER ']' \
'foreach {k v} $vars {\
puts "$k => $v"\
}'
>> editor => vim
>> pager => less
tol -p -a clock format 1234567890
>> Fri Feb 13 23:31:30 UTC 2009
)";
}