-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: truncate history file * chore: husky * chore: husky
- Loading branch information
Showing
9 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn doc:toc && yarn doc:todos && git add . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,8 +323,8 @@ Creates a new program. Options (object, optional) can contain these keys: | |
displays program usage information. | ||
- `version` (boolean, default: true) adds `version` and `--version` to the | ||
program which displays program version from package.json. | ||
- `historyFile` (string, defaults: {homedir}/.bandersnatch_history) is a path to | ||
the app history file. | ||
- `historyFile` (string | null, defaults: {homedir}/.bandersnatch_history) is a | ||
path to the app history file. Set to NULL to disable. | ||
#### `program.description(description)` | ||
|
@@ -680,7 +680,6 @@ Optionally deploy to GitHub, S3, etc. using your preferred CD method if needed. | |
## Todo | ||
|
||
- [ ] Better code coverage | ||
- [ ] History file cleanup (retain first x lines only) | ||
- [ ] Consider resolving ambiguity in _prompt_ param/method | ||
- [ ] Async autocomplete method | ||
- [ ] Choices autocompletion in REPL mode (open upstream PR in yargs) | ||
|
@@ -694,6 +693,7 @@ Contributions are very welcome. | |
git clone [email protected]:hongaar/bandersnatch.git | ||
cd bandersnatch | ||
yarn | ||
yarn husky install | ||
|
||
# Run an example | ||
yarn start examples/foo.ts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import { command, history, History, HISTSIZE, program } from '../src' | ||
|
||
// https://stackoverflow.com/a/52560084/938297 | ||
function tmpFile(name = 'tmp_file', data = '', encoding = 'utf8') { | ||
return new Promise<string>((resolve, reject) => { | ||
const tempPath = path.join(os.tmpdir(), 'bandersnatch-') | ||
fs.mkdtemp(tempPath, (err, folder) => { | ||
if (err) return reject(err) | ||
|
||
const file_name = path.join(folder, name) | ||
|
||
fs.writeFile(file_name, data, encoding, (error_file) => { | ||
if (error_file) return reject(error_file) | ||
|
||
resolve(file_name) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
test('history should return new History object', () => { | ||
const app = program() | ||
|
||
expect(history(app)).toBeInstanceOf(History) | ||
}) | ||
|
||
test('commands should end up in history file', async () => { | ||
const historyFile = await tmpFile('history_file') | ||
const app = program({ historyFile }).add(command('test').action(() => {})) | ||
|
||
await app.run('test') | ||
|
||
expect(fs.readFileSync(historyFile, 'utf8')).toBe('test' + os.EOL) | ||
}) | ||
|
||
test('history file should be truncated', async () => { | ||
const historyFile = await tmpFile( | ||
'history_file', | ||
[...Array(HISTSIZE).keys()].join(os.EOL) + os.EOL | ||
) | ||
const app = program({ historyFile }).add(command('test').action(() => {})) | ||
|
||
await app.run('test') | ||
|
||
expect(fs.readFileSync(historyFile, 'utf8')).toBe( | ||
[...Array(HISTSIZE).keys()].slice(1).join(os.EOL) + os.EOL + 'test' + os.EOL | ||
) | ||
}) | ||
|
||
test('commands should not end up in history file when disabled', async () => { | ||
const historyFile = await tmpFile('history_file') | ||
const app = program({ historyFile: null }).add( | ||
command('test').action(() => {}) | ||
) | ||
|
||
await app.run('test') | ||
|
||
expect(fs.readFileSync(historyFile, 'utf8')).toBe('') | ||
}) |