Skip to content

Commit

Permalink
eb : minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
l-gu committed Jul 13, 2023
1 parent 5378687 commit 9fe10db
Showing 1 changed file with 32 additions and 58 deletions.
90 changes: 32 additions & 58 deletions src/main/java/org/telosys/tools/cli/commands/EditBundleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,81 +55,55 @@ public String getUsage() {
return COMMAND_NAME + " [bundle-name|bundle-partial-name]";
}

// @Override
// public String execute(String[] argsArray) {
// List<String> commandArguments = getArgumentsAsList(argsArray);
// if ( checkHomeDirectoryDefined() && checkArguments(commandArguments, 0, 1 ) ) {
// if ( commandArguments.isEmpty() ) {
// if ( checkBundleDefined() ) {
// editBundle( getCurrentBundle() );
// }
// }
// else {
// editBundle(commandArguments);
// }
// }
// return null ;
// }
@Override
public String execute(String[] argsArray) {
List<String> commandArguments = getArgumentsAsList(argsArray);
if ( checkHomeDirectoryDefined() && checkArguments(commandArguments, 0, 1 ) ) {
File file = null;
if ( commandArguments.isEmpty() ) {
List<String> argsWithoutOptions = removeOptions(commandArguments);
executeEditBundle(argsWithoutOptions);
}
return null ;
}

private void executeEditBundle(List<String> argsWithoutOptions) {
File file = null;
if ( argsWithoutOptions.isEmpty() ) {
// db (no arg) => current bundle if any
if ( checkBundleDefined() ) {
file = getCurrentBundleConfigFile();
}
else {
file = findBundleConfigFile(commandArguments.get(0));
}
if ( file != null ) {
return launchEditor(file.getAbsolutePath());
}
}
return null ;
else if ( argsWithoutOptions.size() == 1 ) {
// db bundle-name => find bundle
file = findBundleConfigFile(argsWithoutOptions.get(0));
}
else {
print("invalid arguments"); // not supposed to happen
return;
}
if ( file != null ) {
editBundleConfigFile(file);
}
}

private void editBundleConfigFile(File file) {
if ( file.exists() && file.isFile() ) {
String r = launchEditor( file.getAbsolutePath() );
print(r);
}
else {
print("No bundle file '" + file.getAbsolutePath() + "'") ;
}
}

private File findBundleConfigFile(String namePattern) {
File bundleFolder = findBundleFolder(namePattern);
if (bundleFolder != null) {
File file = getTelosysProject().getBundleConfigFile(bundleFolder);
if ( file.exists() ) {
return file;
}
else {
print("No configuration file in bundle '" + bundleFolder.getName() + "'") ;
return null;
}
}
return null;
}

// private String editBundle(List<String> commandArguments) {
// try {
// List<String> bundleNames = getInstalledBundles(commandArguments);
// if ( bundleNames.size() > 1 ) {
// print( "Too much bundles found (" + bundleNames.size() + " bundles)") ;
// }
// else if ( bundleNames.size() == 1 ) {
// editBundle(bundleNames.get(0));
// }
// else {
// print("No bundle found.") ;
// }
// } catch (TelosysToolsException e) {
// printError(e);
// }
// return null ;
// }
//
// private String editBundle(String bundleName) {
// File file = getTelosysProject().getBundleConfigFile(bundleName);
// if ( file.exists() ) {
// return launchEditor(file.getAbsolutePath() );
// }
// else {
// print("File '" + file.getAbsolutePath() + "' not found");
// }
// return null ;
// }
//
}

0 comments on commit 9fe10db

Please sign in to comment.