-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Sep 18, 2024
1 parent
5170625
commit a633687
Showing
7 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
import { CmdLet } from '../commands/cmdlet.js'; | ||
import { Output } from '../io/output.js'; | ||
import { Token } from '../io/token.js'; | ||
import { Var } from '../vars/var.js'; | ||
|
||
const USAGE: string = `Usage: cat | ||
cat file - dump file | ||
file the file to dump`; | ||
|
||
export class CatCmdLet extends CmdLet { | ||
name = 'cat'; | ||
category = 'misc'; | ||
help = 'dump a file'; | ||
|
||
public runSync(tokens: Token[]): Var { | ||
const vars = this.transform(tokens, [this.parseLiteral]); | ||
if (vars === null) return this.usage(); | ||
|
||
const [file] = vars as [string]; | ||
Output.writeln(`Dumping file: ${Output.green(file)}`); | ||
|
||
try { | ||
const text = File.readAllText(file); | ||
const lines = text.split('\n'); | ||
lines.forEach(l => Output.writeln(Output.yellow(l), true)); | ||
} catch { | ||
Output.writeln(`failed to read file: ${Output.green(file)}`); | ||
} | ||
|
||
return Var.ZERO; | ||
} | ||
|
||
public usage(): Var { | ||
Output.writeln(USAGE); | ||
return Var.ZERO; | ||
} | ||
} |
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,47 @@ | ||
import { CmdLet } from '../commands/cmdlet.js'; | ||
import { Output } from '../io/output.js'; | ||
import { Token } from '../io/token.js'; | ||
import { Var } from '../vars/var.js'; | ||
|
||
const USAGE: string = `Usage: log | ||
log - clear log file | ||
log file - set log file | ||
file the file to log to`; | ||
|
||
export class LogCmdLet extends CmdLet { | ||
name = 'log'; | ||
category = 'misc'; | ||
help = 'set log file'; | ||
|
||
public runSync(tokens: Token[]): Var { | ||
const vars = this.transformOptional(tokens, [], [this.parseLiteral]); | ||
if (vars === null) return this.usage(); | ||
const [_, [file]] = vars as [[], [string | null]]; | ||
if (file === null) { | ||
Output.clearLog(); | ||
Output.writeln('log file cleared'); | ||
} else { | ||
try { | ||
Output.writeln( | ||
[ | ||
'log file set to ', | ||
Output.blue("'"), | ||
Output.green(file), | ||
Output.blue("'"), | ||
].join(''), | ||
); | ||
Output.setLog(file); | ||
} catch { | ||
Output.writeln(`invalid log file: ${file}`); | ||
} | ||
} | ||
return Var.ZERO; | ||
} | ||
|
||
public usage(): Var { | ||
Output.writeln(USAGE); | ||
return Var.ZERO; | ||
} | ||
} |
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