touch command

This commit is contained in:
Lisa Milne 2023-11-08 09:29:42 +10:00
parent 7fcd7a0694
commit 02f6ee6691

View file

@ -11,6 +11,7 @@ clite.commands.load('ls',function(args,env,io) {
var long = false;
function help() {
io.write(`
ls - list directory contents
Usage: ls [OPTION] [FILE]
Options:
@ -39,7 +40,7 @@ Options:
long = true;
break;
default:
io.error('unknown argument: '+args[i]);
io.error('unknown argument: -'+args[i][j]);
}
}
}else if (args[i][0] == '/') {
@ -82,6 +83,7 @@ clite.commands.load('cat',function(args,env,io) {
function help() {
io.write(`
cat - concatenate files and print to std output or local file
Usage: cat [OPTION] <FILE> [FILE]
Options:
@ -102,7 +104,7 @@ Options:
download = true;
break;
default:
io.error('unknown argument: '+args[i]);
io.error('unknown argument: -'+args[i][j]);
}
}
}else if (args[i][0] == '/') {
@ -162,5 +164,57 @@ Options:
return null;
});
clite.commands.load('touch',function(args,env,io) {
var file = null;
function help() {
io.write(`
touch - create a new empty file
Usage: touch [OPTION] <FILE>
Options:
-? Print this help information
`);
}
for (var i=1; i<args.length; i++) {
if (args[i][0] == '-') {
for (var j=1; j<args[i].length; j++) {
switch (args[i][j]) {
case '?':
help();
return 0;
break;
default:
io.error('unknown argument: -'+args[i][j]);
}
}
}else if (file == null) {
if (args[i][0] == '/') {
file = args[i];
}else{
file = clite.lib.resolvePath(args[i],false);
}
}else{
io.error('unknown argument: '+args[i]);
}
}
if (file == null) {
io.error('no file specified');
return 1;
}
if (!clite.io.creat(file)) {
io.error('unable to create file: '+file);
return 1;
}
return 0;
});
clite.commands.load('less',function(args,env,io) {
return 0;
});
// insert commands above this line
}