File tree Expand file tree Collapse file tree 5 files changed +25
-15
lines changed Expand file tree Collapse file tree 5 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ await Promise.all([
38
38
]);
39
39
40
40
const name = " foo bar" ;
41
- await $ ` mkdir /tmp/${name } ` ;
41
+ await $ ` mkdir /tmp/${name } ` ; // <-- string will be safly quoted to: /tmp/'foo bar'
42
42
```
43
43
44
44
## Content
@@ -107,6 +107,10 @@ Set the current shel.
107
107
108
108
Set the current working directory.
109
109
110
+ ### ` $.quote `
111
+
112
+ Parser method that is used to safely quote strings. Used by: `` $`command` ``
113
+
110
114
### `` $`command` ``
111
115
112
116
``` ts
@@ -152,7 +156,7 @@ try {
152
156
153
157
### ` cd() `
154
158
155
- Set the current working directory. Also available on the global ` $ ` symbol .
159
+ Set the current working directory. If path does not exist, an error is thrown .
156
160
157
161
### ` $.[style]() `
158
162
@@ -162,6 +166,11 @@ dzx has chainable color methods that are available on the global `$` symbol.
162
166
console .log ($ .blue .bold (" Hello world!" ));
163
167
```
164
168
169
+ ### `` quote`string` ``
170
+
171
+ The quote methods quotes safly a string. by default the ` shq ` package is used.
172
+ Can be overidden with ` $.quote ` .
173
+
165
174
## Remote usage
166
175
167
176
``` typescript
Original file line number Diff line number Diff line change 2
2
3
3
import { join , readAll } from "./deps.ts" ;
4
4
import { ProcessError } from "./src/process_error.ts" ;
5
- import { $ } from "./mod.ts" ;
5
+ import { $ , cd , quote } from "./mod.ts" ;
6
6
7
7
window . $ = $ ;
8
- window . cd = $ . cd ;
8
+ window . cd = cd ;
9
+ window . quote = quote ;
9
10
10
11
const script : string | undefined = Deno . args [ 0 ] ;
11
12
Original file line number Diff line number Diff line change 1
- import { colors } from "./deps.ts" ;
1
+ import { colors , escapeStr } from "./deps.ts" ;
2
2
import { cd } from "./src/cd.ts" ;
3
3
import { exec } from "./src/exec.ts" ;
4
4
import { quote } from "./src/quote.ts" ;
@@ -7,19 +7,19 @@ export type $ = typeof exec & typeof colors & {
7
7
verbose : boolean ;
8
8
cwd : string ;
9
9
shell : string ;
10
- cd : typeof cd ;
11
- quote : typeof quote ;
10
+ quote : typeof escapeStr ;
12
11
} ;
13
12
14
13
export const $ : $ = exec as $ ;
15
14
15
+ export { quote } ;
16
+
16
17
Object . setPrototypeOf ( $ , Object . getPrototypeOf ( colors ) ) ;
17
18
18
19
$ . _stack = [ ] ;
19
20
$ . shell = "/bin/sh" ;
20
21
$ . verbose = false ;
21
22
$ . cwd = Deno . cwd ( ) ;
22
- $ . cd = cd ;
23
- $ . quote = quote ;
23
+ $ . quote = escapeStr ;
24
24
25
25
export { cd } ;
Original file line number Diff line number Diff line change 1
- import { escapeStr } from "../deps.ts" ;
2
-
3
1
export function quote (
4
2
pieces : TemplateStringsArray ,
5
3
...args : Array < string | number >
@@ -8,7 +6,7 @@ export function quote(
8
6
let i = 0 ;
9
7
for ( ; i < args . length ; i ++ ) {
10
8
if ( typeof args [ i ] === "string" ) {
11
- parsed += escapeStr ( args [ i ] as string ) + pieces [ i + 1 ] ;
9
+ parsed += $ . quote ( args [ i ] as string ) + pieces [ i + 1 ] ;
12
10
} else {
13
11
parsed += args [ i ] + pieces [ i + 1 ] ;
14
12
}
Original file line number Diff line number Diff line change 1
- import type { $ } from "./mod.ts" ;
1
+ import type { $ , cd as _cd , quote as _quote } from "./mod.ts" ;
2
2
3
3
declare global {
4
4
const $ : $ ;
5
- const cd : typeof $ . cd ;
5
+ const cd : typeof _cd ;
6
+ const quote : typeof _quote ;
6
7
7
8
interface Window {
8
9
$ : $ ;
9
- cd : typeof $ . cd ;
10
+ cd : typeof _cd ;
11
+ quote : typeof _quote ;
10
12
}
11
13
}
You can’t perform that action at this time.
0 commit comments