Updates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
async function run(ctx, argv) {
|
||||
ctx.console.log(
|
||||
'Bare OS — default user: guest | builtins: cd, export, exit, login, logout | /bin: basename cat clear crontab date dirname echo env exit false grep head hdms help hostname id login logout ls nl pathchk printenv pwd rm savevault seq sleep sort tail test touch true tty uname wc which whoami'
|
||||
'Bare OS — default user: guest | builtins: alias, cd, export, exit, login, logout, unalias | /bin: basename cat clear crontab date dirname echo env exit false git grep head hdms help hostname id login logout ls nl pathchk printenv pwd rm savevault seq sleep sort tail test touch true tty uname wc which whoami'
|
||||
)
|
||||
ctx.console.log(
|
||||
'Identity: login [--new] <passphrase> | logout [--save] | savevault (encrypt copy of personal drive under /.bare/vault/)'
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
/**
|
||||
* rm — remove files or directories.
|
||||
* Flags: -r -R --recursive, -f --force, -- ; bundled e.g. -rf
|
||||
*/
|
||||
async function run(ctx, argv) {
|
||||
const vfs = ctx.vfs
|
||||
let recursive = false
|
||||
let force = false
|
||||
const files = []
|
||||
let dash = false
|
||||
for (let i = 1; i < argv.length; i++) {
|
||||
@@ -11,7 +18,22 @@ async function run(ctx, argv) {
|
||||
dash = true
|
||||
continue
|
||||
}
|
||||
if (a.startsWith('-')) continue
|
||||
if (a === '--recursive' || a === '-r' || a === '-R') {
|
||||
recursive = true
|
||||
continue
|
||||
}
|
||||
if (a === '--force' || a === '-f') {
|
||||
force = true
|
||||
continue
|
||||
}
|
||||
if (a.startsWith('-') && a.length > 1) {
|
||||
for (let j = 1; j < a.length; j++) {
|
||||
const c = a[j]
|
||||
if (c === 'r' || c === 'R') recursive = true
|
||||
else if (c === 'f') force = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
files.push(a)
|
||||
}
|
||||
if (!files.length) {
|
||||
@@ -19,10 +41,18 @@ async function run(ctx, argv) {
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
const doRm =
|
||||
vfs && typeof vfs.rm === 'function'
|
||||
? (p) => vfs.rm(p, { recursive, force })
|
||||
: async (p) => {
|
||||
if (recursive) throw new Error('recursive rm not supported')
|
||||
return vfs.unlink(p)
|
||||
}
|
||||
for (const f of files) {
|
||||
try {
|
||||
await ctx.vfs.unlink(f)
|
||||
await doRm(f)
|
||||
} catch (e) {
|
||||
if (force) continue
|
||||
ctx.console.error('rm: ' + f + ': ' + (e.message || e))
|
||||
ctx.exitCode = 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user