Skip to content

Commit b7a66be

Browse files
committed
💥 use config instead of set()
1 parent 7ebe198 commit b7a66be

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ mkdir(join(tempdir(), name));
3434
· [pushd](https://github.com/shelljs/shelljs#pushdoptions-dir---n--n) · [popd](https://github.com/shelljs/shelljs#popdoptions--n--n) · [dirs](https://github.com/shelljs/shelljs#dirsoptions--n---n) · [exec](https://github.com/shelljs/shelljs#execcommand--options--callback)
3535
· [find](https://github.com/shelljs/shelljs#findpath--path-) · [grep](https://github.com/shelljs/shelljs#grepoptions-regex_filter-file--file-) · [head](https://github.com/shelljs/shelljs#head-n-num-file--file-) · [ln](https://github.com/shelljs/shelljs#lnoptions-source-dest)
3636
· [ls](https://github.com/shelljs/shelljs#lsoptions-path-) · [mkdir](https://github.com/shelljs/shelljs#mkdiroptions-dir--dir-) · [mv](https://github.com/shelljs/shelljs#mvoptions--source--source--dest) · [pwd](https://github.com/shelljs/shelljs#pwd)
37-
· [rm](https://github.com/shelljs/shelljs#rmoptions-file--file-) · [sed](https://github.com/shelljs/shelljs#sedoptions-search_regex-replacement-file--file-) · [set](https://github.com/shelljs/shelljs#setoptions) · [sort](https://github.com/shelljs/shelljs#sortoptions-file--file-)
37+
· [rm](https://github.com/shelljs/shelljs#rmoptions-file--file-) · [sed](https://github.com/shelljs/shelljs#sedoptions-search_regex-replacement-file--file-) · [sort](https://github.com/shelljs/shelljs#sortoptions-file--file-)
3838
· [tail](https://github.com/shelljs/shelljs#tail-n-num-file--file-) · [tempdir](https://github.com/shelljs/shelljs#tempdir) · [test](https://github.com/shelljs/shelljs#testexpression) · [touch](https://github.com/shelljs/shelljs#touchoptions-file--file-)
3939
· [uniq](https://github.com/shelljs/shelljs#uniqoptions-input-output) · [which](https://github.com/shelljs/shelljs#whichcommand) · [exit](https://github.com/shelljs/shelljs#exitcode) · [error](https://github.com/shelljs/shelljs#error) · [errorCode](https://github.com/shelljs/shelljs#errorcode)
4040
| another libs: [cli()](#cli) · [chalk](#chalk-package) · [fetch()](#fetch)
41-
| this lib: [xarg()](#xarg) · [pipe()](#pipe) · [question()](#question) · [echo()](#echo) · [exec$()](#exec$) · [stdin()](#stdin)
41+
| this lib: [xarg()](#xarg) · [pipe()](#pipe) · [question()](#question) · [echo()](#echo) · [exec$()](#exec$) · [stdin()](#stdin) · [config](#config)
4242

4343

4444
## Documentation
@@ -149,6 +149,17 @@ Returns the stdin as a string.
149149
const content= JSON.parse(await stdin());
150150
```
151151

152+
### `config`
153+
Read/write global configuration.
154+
155+
- `verbose`: Will print each executed command to the screen.
156+
- `fatal`: If true the script will die on errors.
157+
- `noglob`: Disable filename expansion (globbing)
158+
159+
```js
160+
const { verbose, fatal, noglob }= config;
161+
```
162+
152163
### `chalk` package
153164
The [chalk](https://www.npmjs.com/package/chalk) package. Also as shorthand **s**.
154165

index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ export const {
3030
test, error,
3131
cat, sed, grep, sort, head, tail, uniq,
3232
which,
33-
exit, env, set,
34-
exec,
35-
config
33+
exit, env,
34+
exec
3635
}= shelljs;
3736
/**
3837
* Silent execution of {@link exec} to be used with pipeing or as variable.
@@ -47,6 +46,25 @@ export function exec$(command, options= {}){
4746
return exec(command, Object.assign({}, options, { async: false, silent: true })).replace(/\n$/g, "");
4847
}
4948

49+
const _config= shelljs.config;
50+
export const config= {
51+
/** Will print each executed command to the screen.
52+
* @default false
53+
*/
54+
get verbose(){ return _config.verbose; },
55+
set verbose(v){ return (_config.verbose = v); },
56+
/** If true the script will die on errors. Default is false. */
57+
get fatal(){ return _config.fatal; },
58+
set fatal(v){ return (_config.fatal = v); },
59+
/** Disable filename expansion (globbing) */
60+
get noglob(){ return _config.noglob; },
61+
set noglob(v){ return (_config.noglob = v); },
62+
/** Set multiple options with one command.
63+
* @param {...Record<"verbose"|"fatal"|"noglob",boolean>} c
64+
* */
65+
assign(...c){ return Object.assign(this, ...c); }
66+
};
67+
5068
import chalk from "chalk";
5169
export { chalk, chalk as s };
5270

0 commit comments

Comments
 (0)