added disk cli program
This commit is contained in:
parent
95a9ab63d0
commit
a87f50eec7
139
src/bin/Disk.hx
Normal file
139
src/bin/Disk.hx
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package bin;
|
||||||
|
|
||||||
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
import lib.cli.TermHandle;
|
||||||
|
import lib.cli.CLIBase;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
using Lambda;
|
||||||
|
|
||||||
|
class Disk extends CLIBase {
|
||||||
|
|
||||||
|
private var handle:TermHandle;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invoke(handle:TermHandle):Future<Bool> {
|
||||||
|
this.handle = handle;
|
||||||
|
var subcommand = handle.args[0];
|
||||||
|
var driveAddr:Null<String> = handle.args[1];
|
||||||
|
|
||||||
|
switch (subcommand) {
|
||||||
|
case "ls":
|
||||||
|
Peripheral.instance.getDrives().foreach(drive -> {
|
||||||
|
var addr = drive.getAddr();
|
||||||
|
var label = drive.getDiskLabel();
|
||||||
|
var id = drive.getDiskID();
|
||||||
|
|
||||||
|
if (drive.isDiskPresent()){
|
||||||
|
if (drive.hasAudio()){
|
||||||
|
handle.writeLn('${addr} => ${label} [AUDIO]');
|
||||||
|
}else{
|
||||||
|
handle.writeLn('${addr} => ${label} (${id})');
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
handle.writeLn('${addr} => [NO DISK]');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
case "play":
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLn("Drive not found: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLn("No disk in drive: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.hasAudio()){
|
||||||
|
handle.writeLn("Disk in drive " + driveAddr + " does not have audio");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
drive.playAudio();
|
||||||
|
case "stop":
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLn("Drive not found: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLn("No disk in drive: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.hasAudio()){
|
||||||
|
handle.writeLn("Disk in drive: " + driveAddr + " does not have audio");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
drive.stopAudio();
|
||||||
|
|
||||||
|
case "eject":
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLn("Drive not found: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLn("No disk in drive: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
drive.ejectDisk();
|
||||||
|
case "lable":
|
||||||
|
var drive = Peripheral.instance.getDrive(driveAddr);
|
||||||
|
var label:String = handle.args[2];
|
||||||
|
|
||||||
|
if (drive == null){
|
||||||
|
handle.writeLn("Drive not found: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!drive.isDiskPresent()){
|
||||||
|
handle.writeLn("No disk in drive: " + driveAddr);
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (label == null || label == ""){
|
||||||
|
handle.writeLn(drive.getDiskLabel());
|
||||||
|
}else{
|
||||||
|
var err = drive.setDiskLabel(label);
|
||||||
|
if (err != null){
|
||||||
|
handle.writeLn("Failed to set lable");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "help":
|
||||||
|
case null:
|
||||||
|
printHelp();
|
||||||
|
default:
|
||||||
|
handle.writeLn("Unknown subcommand: " + subcommand);
|
||||||
|
printHelp();
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Future.sync(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function printHelp() {
|
||||||
|
handle.writeLn("Usage: disk <subcommand> [args]");
|
||||||
|
handle.writeLn("Subcommands:");
|
||||||
|
handle.writeLn(" ls");
|
||||||
|
handle.writeLn(" play <drive>");
|
||||||
|
handle.writeLn(" stop <drive>");
|
||||||
|
handle.writeLn(" eject <drive>");
|
||||||
|
handle.writeLn(" label <drive> [label]");
|
||||||
|
}
|
||||||
|
}
|
@ -143,6 +143,8 @@ class Terminal {
|
|||||||
return new Net();
|
return new Net();
|
||||||
case "rs":
|
case "rs":
|
||||||
return new Redstone();
|
return new Redstone();
|
||||||
|
case "disk":
|
||||||
|
return new Disk();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user