mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
new: server tab process
This commit is contained in:
41
lib/data/model/app/shell_func.dart
Normal file
41
lib/data/model/app/shell_func.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user