new: server tab process

This commit is contained in:
lollipopkit
2023-06-21 17:47:57 +08:00
parent 625bc280f0
commit 3a8e189dd7
14 changed files with 111 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
class AppShellFunc {
final String name;
final String cmd;
final String flag;
const AppShellFunc(this.name, this.cmd, this.flag);
}
typedef AppShellFuncs = List<AppShellFunc>;
extension AppShellFuncsExt on AppShellFuncs {
String get generate {
final sb = StringBuffer();
// Write each func
for (final func in this) {
sb.write('''
${func.name}() {
${func.cmd}
}
''');
}
// Write switch case
sb.write('case \$1 in\n');
for (final func in this) {
sb.write('''
'-${func.flag}')
${func.name}
;;
''');
}
sb.write('''
*)
echo "Invalid argument \$1"
;;
esac
''');
return sb.toString();
}
}