Skip to content

Commit 05fc05d

Browse files
committed
docs(touch): clarify docs for touch() command
No change to logic. This expands on the `touch()` command documentation to make it more obvious how to use multiple options, long options, etc. This also renames a variable in a test case to make the usage more obvious.
1 parent 9a0e5f6 commit 05fc05d

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,17 +681,18 @@ Available options:
681681
+ `-a`: Change only the access time
682682
+ `-c`: Do not create any files
683683
+ `-m`: Change only the modification time
684-
+ `{'-d': someDate}`, `{date: someDate}`: Use `someDate` (instance of
685-
`Date`) instead of current time
684+
+ `{'-d': someDate}`, `{date: someDate}`: Use a `Date` instance (ex. `someDate`)
685+
instead of current time
686686
+ `{'-r': file}`, `{reference: file}`: Use `file`'s times instead of current
687-
time
687+
time
688688

689689
Examples:
690690

691691
```javascript
692692
touch('source.js');
693693
touch('-c', 'path/to/file.js');
694694
touch({ '-r': 'referenceFile.txt' }, 'path/to/file.js');
695+
touch({ '-d': new Date('December 17, 1995 03:24:00'), '-m': true }, 'path/to/file.js');
695696
touch({ date: new Date('December 17, 1995 03:24:00') }, 'path/to/file.js');
696697
```
697698

src/touch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ common.register('touch', _touch, {
2020
//@ + `-a`: Change only the access time
2121
//@ + `-c`: Do not create any files
2222
//@ + `-m`: Change only the modification time
23-
//@ + `{'-d': someDate}`, `{date: someDate}`: Use `someDate` (instance of
24-
//@ `Date`) instead of current time
23+
//@ + `{'-d': someDate}`, `{date: someDate}`: Use a `Date` instance (ex. `someDate`)
24+
//@ instead of current time
2525
//@ + `{'-r': file}`, `{reference: file}`: Use `file`'s times instead of current
26-
//@ time
26+
//@ time
2727
//@
2828
//@ Examples:
2929
//@
3030
//@ ```javascript
3131
//@ touch('source.js');
3232
//@ touch('-c', 'path/to/file.js');
3333
//@ touch({ '-r': 'referenceFile.txt' }, 'path/to/file.js');
34+
//@ touch({ '-d': new Date('December 17, 1995 03:24:00'), '-m': true }, 'path/to/file.js');
3435
//@ touch({ date: new Date('December 17, 1995 03:24:00') }, 'path/to/file.js');
3536
//@ ```
3637
//@

test/touch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ test('accepts -d flag', t => {
129129
t.is(common.statFollowLinks(testFile).atime.getTime(), date.getTime());
130130
});
131131

132-
test('accepts long option (date)', t => {
132+
test('accepts long option (--date)', t => {
133133
const testFile = tmpFile(t);
134-
const date = new Date('December 17, 1995 03:24:00');
135-
const result = shell.touch({ date }, testFile);
134+
const someDate = new Date('December 17, 1995 03:24:00');
135+
const result = shell.touch({ date: someDate }, testFile);
136136
t.is(result.code, 0);
137137
// Compare getTime(), because Date can't be compared with triple-equals.
138-
t.is(common.statFollowLinks(testFile).mtime.getTime(), date.getTime());
139-
t.is(common.statFollowLinks(testFile).atime.getTime(), date.getTime());
138+
t.is(common.statFollowLinks(testFile).mtime.getTime(), someDate.getTime());
139+
t.is(common.statFollowLinks(testFile).atime.getTime(), someDate.getTime());
140140
});
141141

142142
test('sets mtime and atime by default', t => {

0 commit comments

Comments
 (0)