You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-80Lines changed: 33 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,11 @@ SODA is a simple platform to help writing and executing tasks in shell script.
4
4
5
5
## How It Works
6
6
7
-
SODA works by loading any scripts in a specific directory and calling a function
8
-
passed by the command line. Only functions exposes through the builtin **task** function
9
-
may be called.
7
+
SODA works by loading any scripts in a specific directory and calling a function passed by the command line. Only functions exposes through the builtin **task** function may be called.
10
8
11
9
## How To Install
12
10
13
-
Just clone the git repo and place the *soda* file in your path (a symlinks works well to).
14
-
After that, ensure you have a **$SODA_HOME** pointing to the place you clone the repo and you're
15
-
done.
11
+
Just clone the git repo and place the *soda* file in your path (a symlinks works well to). After that, ensure you have a **$SODA_HOME** pointing to the place you clone the repo and you're done.
16
12
17
13
## How To Use
18
14
@@ -22,11 +18,9 @@ Create a *~/.soda* directory with the following structure:
22
18
*_config_ - directory to put the configuration files organized by namespaces
23
19
* Any other directory you like, still organized by namespaces
24
20
25
-
You can also use the same directory you install soda without configure the user directory. You can
26
-
access any file in that directories by using the **exists** function.
21
+
You can also use the same directory you install soda without configure the user directory. You can access any file in that directories by using the **exists** function.
27
22
28
-
Inside *scripts*, any function in any script present in *scripts/common* and exposed through
29
-
**task** can be invoked:
23
+
Inside *scripts*, any function in any script present in *scripts/common* and exposed through **task** can be invoked:
30
24
31
25
task "git-open" "Creates a new branch off master"
32
26
git_open() {
@@ -39,19 +33,15 @@ Inside *scripts*, any function in any script present in *scripts/common* and exp
39
33
40
34
$ soda git-open work
41
35
42
-
This will call the *git_open* function passing *work* as the arguments. By convention, you
43
-
may call a function with underscores replacing them by hyphens. To execute the task without
44
-
arguments, just use `soda git-open`.
36
+
This will call the *git_open* function passing *work* as the arguments. By convention, you may call a function with underscores replacing them by hyphens. To execute the task without arguments, just use `soda git-open`.
45
37
46
38
To see the program usage, type `soda`, `soda help` or `soda --help`.
47
39
48
40
## Task Namespaces
49
41
50
-
The namespaces are simply directories in _scripts_. By default, the *common* and *soda* namespaces
51
-
are always imported. You can include other namespaces using the **import** function.
42
+
The namespaces are simply directories in _scripts_. By default, the *common* and *soda* namespaces are always imported. You can include other namespaces using the **import** function.
52
43
53
-
Namespaces are useful if you have a set of scripts that you should use only on specific cases. (It
54
-
also keeps your scripts organized.)
44
+
Namespaces are useful if you have a set of scripts that you should use only on specific cases. (It also keeps your scripts organized.)
55
45
56
46
# Example: script inside ~/.soda/scripts/git
57
47
@@ -80,15 +70,11 @@ You can call any task in *git* namespace using a **"."**:
80
70
81
71
$ soda git.push
82
72
83
-
The **"."** indicates that namespace is the first part and task is the second part. To see a help
84
-
message for only one namespace, use `soda help NAMESPACE` (additionally, you can place a `info` file
85
-
in the scripts folder for a namespace to make its contents appear in the help message).
73
+
The **"."** indicates that namespace is the first part and task is the second part. To see a help message for only one namespace, use `soda help NAMESPACE` (additionally, you can place a `info` file in the scripts folder for a namespace to make its contents appear in the help message).
86
74
87
75
## Task Parameters
88
76
89
-
If you need to pass a set of parameters, you can use --OPTION_NAME in case of a boolean option or
90
-
--OPTION_NAME=OPTION_VALUE. The parameters will be translated replacing hyphens with underscores
91
-
(but ignoring the prefix **--**) **with upper case**.
77
+
If you need to pass a set of parameters, you can use --OPTION_NAME in case of a boolean option or --OPTION_NAME=OPTION_VALUE. The parameters will be translated replacing hyphens with underscores (but ignoring the prefix **--**) **with upper case**.
92
78
93
79
$ soda --my-option=test
94
80
@@ -97,8 +83,7 @@ If you need to pass a set of parameters, you can use --OPTION_NAME in case of a
97
83
# some code
98
84
fi
99
85
100
-
To register a parameter in the program usage, use the *parameter* function (for more details, see
101
-
the documentation bellow). The registered parameters will also be available for bash completion.
86
+
To register a parameter in the program usage, use the *parameter* function (for more details, see the documentation bellow). The registered parameters will also be available for bash completion.
102
87
103
88
Keep in mind that **any** parameter will be converted to a variable (even those not exposed).
104
89
@@ -117,8 +102,7 @@ The builtin events are:
117
102
118
103
***start** - before the task execution
119
104
***finish** - after the task execution
120
-
***fail***(exit code)* - when a command fails to execute (broadcasted by *execute* and *check*
121
-
functions)
105
+
***fail***(exit code)* - when a command fails to execute (broadcasted by *execute* and *check* functions)
122
106
123
107
## Quick Tasks
124
108
@@ -137,10 +121,7 @@ Any directory in the form `bin/$NAMESPACE` in both `$SODA_HOME` or `$SODA_USER_H
137
121
138
122
## Bash Completion
139
123
140
-
SODA supports bash completion by importing all namespaces and searching for defined parameters
141
-
and tasks. To enable bash completion, use the file **soda-bash-completion** (you can source it,
142
-
copy to */etc/bash_completion.d/* or using your preferred way). The default bash completion proposes
143
-
tasks and parameters.
124
+
SODA supports bash completion by importing all namespaces and searching for defined parameters and tasks. To enable bash completion, use the file **soda-bash-completion** (you can source it, copy to */etc/bash_completion.d/* or using your preferred way). The default bash completion proposes tasks and parameters.
144
125
145
126
$ soda he[TAB]
146
127
$ soda help
@@ -163,8 +144,7 @@ Alternatively, you can use the **suggest** function to map the bash completion f
163
144
echo "bar"
164
145
}
165
146
166
-
If a parameter is passed after the task declaration in command line, the suggestions will be only
167
-
the parameters for the task namespace.
147
+
If a parameter is passed after the task declaration in command line, the suggestions will be only the parameters for the task namespace.
168
148
169
149
# namespace my-namespace
170
150
@@ -177,44 +157,32 @@ the parameters for the task namespace.
177
157
$ soda my-namespace.my-task --[TAB]
178
158
$ soda my-namespace.my-task --option
179
159
180
-
It is important to remember that logs and event broadcasting are disabled while SODA is in bash
181
-
completion mode.
160
+
It is important to remember that logs and event broadcasting are disabled while SODA is in bash completion mode.
182
161
183
162
## Configuration
184
163
185
-
Every namespace has it own configuration dir in $SODA_USER_HOME/config/NAMESPACE. Any configuration
186
-
file will be loaded in that directory at namespace import **before** loading script files.
164
+
Every namespace has it own configuration dir in $SODA_USER_HOME/config/NAMESPACE. Any configuration file will be loaded in that directory at namespace import **before** loading script files.
187
165
188
-
You can configure **soda** namespace through a **$SODA_USER_HOME/conf/soda/soda.conf** file (or any
189
-
other name but inside that directory). The supported properties are:
166
+
You can configure **soda** namespace through a **$SODA_USER_HOME/conf/soda/soda.conf** file (or any other name but inside that directory). The supported properties are:
190
167
191
168
***LOG_FILE** - The log file (defaults to *$SODA_HOME/log/soda.log*)
192
-
***SODA_NAMESPACE_DELIMITER** - The namespace delimiter (defaults to **.**). Changing this also
193
-
affects the bash completion
194
-
***SODA_TASK_BASH_COMPLETION_SUFFIX** - The suffix to build the function for custom bash completion
195
-
(defaults to *_bash_completion*)
169
+
***SODA_NAMESPACE_DELIMITER** - The namespace delimiter (defaults to **.**). Changing this also affects the bash completion
170
+
***SODA_TASK_BASH_COMPLETION_SUFFIX** - The suffix to build the function for custom bash completion (defaults to *_bash_completion*)
196
171
***SODA_FILE_LOG_PATTERN** - The pattern to format logs that goes in *LOG_FILE*
197
172
***SODA_CONSOLE_LOG_PATTERN** - The pattern to format logs that goes in console
198
173
***SODA_FUNCTION_NAME_LENGTH** - The max length to format the function name in the help usage
199
174
***SODA_PARAMETER_NAME_LENGTH** - The max length to format the parameter names in the help usage
200
-
***SODA_PARAMETER_NAMESPACE_LENGTH** - The max length to format the parameter namespace in the help
201
-
usage
202
-
***SODA_DEFAULT_RESOURCE_DIR** - the default directory to search for resources (defaults to
203
-
*resources*)
175
+
***SODA_PARAMETER_NAMESPACE_LENGTH** - The max length to format the parameter namespace in the help usage
176
+
***SODA_DEFAULT_RESOURCE_DIR** - the default directory to search for resources (defaults to *resources*)
204
177
***SODA_TASK_OPTIONAL_PREFIX** - the optional prefix to map a task function (defaults to *do_*)
205
178
206
-
Remember that parameters are converted to upper case, so you can call `soda --log-file=path/to/file`
207
-
and the *$LOG_FILE* variable will be set to that value.
179
+
Remember that parameters are converted to upper case, so you can call `soda --log-file=path/to/file` and the *$LOG_FILE* variable will be set to that value.
208
180
209
-
The parameter **SODA_TASK_OPTIONAL_PREFIX** is very usefull in case of tasks with a name already
210
-
defined by another function or name (*kill* or *status*, for example). To avoid conflicts, prefix
211
-
the function with the SODA_TASK_OPTIONAL_PREFIX value (*do_kill*, *do_status*, ...).
181
+
The parameter **SODA_TASK_OPTIONAL_PREFIX** is very usefull in case of tasks with a name already defined by another function or name (*kill* or *status*, for example). To avoid conflicts, prefix the function with the SODA_TASK_OPTIONAL_PREFIX value (*do_kill*, *do_status*, ...).
212
182
213
183
## Logging
214
184
215
-
To log something, just call the **log** function passing the category and message (optionally, you
216
-
can pass a color for showing in console). There are some aliases for calling log with a predefined
217
-
category:
185
+
To log something, just call the **log** function passing the category and message (optionally, you can pass a color for showing in console). There are some aliases for calling log with a predefined category:
218
186
219
187
***log_debug** - uses the DEBUG category
220
188
***log_info** - uses the INFO category
@@ -235,20 +203,15 @@ If you want to use another log system (a *syslog* or another) just define a **lo
235
203
236
204
## Builtin functions
237
205
238
-
The builtin functions are present in *scripts/soda* dir and the *scripts/core.sh*, the
239
-
most significant are listed below:
206
+
The builtin functions are present in *scripts/soda* dir and the *scripts/core.sh*, the most significant are listed below:
Register the given function as a task and enables invoking it. You may pass the function
244
-
args in *$function_name*. If a description is given, expose the given function in the program usage
245
-
and register it for autocompletion.
210
+
Register the given function as a task and enables invoking it. You may pass the function args in *$function_name*. If a description is given, expose the given function in the program usage and register it for autocompletion.
Register the given parameter and returns indicating if the parameter was given. The parameter value
250
-
is accessible through the variable $parameter_name in upper case with hyphens replaced by
251
-
underscores.
214
+
Register the given parameter and returns indicating if the parameter was given. The parameter value is accessible through the variable $parameter_name in upper case with hyphens replaced by underscores.
252
215
253
216
parameter "help" "Prints this help message" && {
254
217
usage
@@ -260,19 +223,15 @@ underscores.
260
223
261
224
### exists ([type] path)
262
225
263
-
Checks if the file $SODA_USER_HOME/$type/$NAMESPACE/$path exists using the namespace of the invoked
264
-
task or imported namespace. The file path will be stored in the $FILE variable. If the *type* is not
265
-
passed then **resources** will be used.
226
+
Checks if the file $SODA_USER_HOME/$type/$NAMESPACE/$path exists using the namespace of the invoked task or imported namespace. The file path will be stored in the $FILE variable. If the *type* is not passed then **resources** will be used.
266
227
267
228
exists config "my-config.conf" && {
268
229
source $FILE
269
230
}
270
231
271
232
### resource ([type] path)
272
233
273
-
Returns the file $SODA_USER_HOME/$type/$NAMESPACE/$path using the namespace of the invoked task or
274
-
imported namespace without checking if the file exists. If the *type* is not passed then
275
-
**resources** will be used. For use with the **config** type, use the `config` builtin function.
234
+
Returns the file $SODA_USER_HOME/$type/$NAMESPACE/$path using the namespace of the invoked task or imported namespace without checking if the file exists. If the *type* is not passed then **resources** will be used. For use with the **config** type, use the `config` builtin function. The `config` function redirects to the resource function using *config* as the first parameter and the given parameter as the second parameter.
276
235
277
236
### invoke (description, function_name)
278
237
@@ -288,13 +247,11 @@ Asks user about something and indicates if the answer is **yes** or **no**.
288
247
289
248
### check (description)
290
249
291
-
Checks if the previous command returned successfully and logs the result using the given
292
-
description.
250
+
Checks if the previous command returned successfully and logs the result using the given description.
293
251
294
252
### execute (description, command, [*args])
295
253
296
-
Executes a command and checks if it was sucessfull. The output will be stored in the variable
297
-
*$LAST_EXECUTION_OUTPUT* and the result will be .
254
+
Executes a command and checks if it was sucessfull. The output will be stored in the variable *$LAST_EXECUTION_OUTPUT* and the result will be .
298
255
299
256
execute "Pushing commits" git push
300
257
# outputs according to exit code:
@@ -303,8 +260,7 @@ Executes a command and checks if it was sucessfull. The output will be stored in
Asks the user to input a value. The value will be stored in the indicated variable. If the variable
307
-
name is in upper case and is already set, the prompt will be skipped.
263
+
Asks the user to input a value. The value will be stored in the indicated variable. If the variable name is in upper case and is already set, the prompt will be skipped.
308
264
309
265
input "Server address" "SERVER" "localhost"
310
266
input "User name" "USER_NAME" "$(whoami)"
@@ -313,9 +269,7 @@ name is in upper case and is already set, the prompt will be skipped.
313
269
314
270
### choose (description, variable, *options)
315
271
316
-
Asks user to choose a value from a list of options and stores the 0-based index
317
-
of the selected value and the label in the $variable_label var. If the variable name
318
-
is in upper case and is already set, the prompt will be skipped.
272
+
Asks user to choose a value from a list of options and stores the 0-based index of the selected value and the label in the $variable_label var. If the variable name is in upper case and is already set, the prompt will be skipped.
0 commit comments