Select Git revision
method.dart 2.09 KiB
import 'package:scp_meta/copy.dart';
import 'package:scp_meta/options.dart';
import 'package:scp_meta/storage.dart';
class Method {
final Storage src;
final Storage dst;
final Copy method;
final Options opt;
/// konstruktor
Method(this.src, this.dst, this.method, this.opt);
String selectCommand(bool cond, String command, String last) {
if (cond == true) {
print('+ $command'); // DEBUG
return (last.isEmpty) ? command : last;
}
else {
print('- $command'); // DEBUG
return last;
}
}
String getCommand() {
String best = '';
print("SRC: ${src.getFqdn()} -> DST: ${dst.getFqdn()}");
best = selectCommand(
src.getFqdn() == dst.getFqdn() && src.isScpRemote(),
"ssh ${src.getAsSsh()} 'cp ${opt.getAsCp()} ${src.getScpPath()} ${dst.getScpPath()}'",
best);
best = selectCommand(
src.isScpDirect() && dst.isScpRemote(),
"scp ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsScp()}",
best);
best = selectCommand(
src.isScpRemote() && dst.isScpDirect() && !opt.isDefinedPort(),
"ssh ${dst.getAsSsh()} 'scp ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsCp()}'",
best);
best = selectCommand(
src.isScpRemote() && dst.isScpRemote(),
"scp -3 ${opt.getAsScp(remove:['3'])} ${src.getAsScp()} ${dst.getAsScp()}",
best);
best = selectCommand(
src.isCopy() && dst.isScpRemote(),
"scp ${opt.getAsCp()} ${src.getAsCp()} ${dst.getAsScp()}",
best);
best = selectCommand(
src.isScpRemote() && dst.isCopy(),
"scp ${opt.getAsScp()} ${src.getAsCp()} ${dst.getAsScp()}",
best);
best = selectCommand(
src.isScpRemote() && dst.isCopy(),
"scp ${opt.getAsScp()} ${src.getAsScp()} ${dst.getAsCp()}",
best);
best = selectCommand(
true,
"scp ${opt.getAsScp()} ${src.getAsOrigin()} ${dst.getAsOrigin()}",
best);
return best;
}
String getAsCp() {
return opt.getAsCp();
}
@override
String toString() {
return getCommand();
}
}