Skip to content

Commit

Permalink
Merge pull request #192 from Screenly/feature/2/update_entrypoint
Browse files Browse the repository at this point in the history
Removes: args from edge apps commands.
  • Loading branch information
korvyashka authored Jul 19, 2024
2 parents fc6efa1 + 0fe528e commit 6052f3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 74 deletions.
81 changes: 28 additions & 53 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ pub enum EdgeAppCommands {
#[arg(short, long)]
path: Option<String>,

/// Edge App id. If not specified CLI will use the id from the manifest.
#[arg(short, long)]
app_id: Option<String>,

/// Edge App name
#[arg(short, long)]
name: String,
Expand Down Expand Up @@ -341,10 +337,6 @@ pub enum EdgeAppCommands {
#[arg(short, long)]
path: Option<String>,

/// Edge App id. If not specified CLI will use the id from the manifest.
#[arg(short, long)]
app_id: Option<String>,

#[arg(short, long)]
delete_missing_settings: Option<bool>,
},
Expand All @@ -353,10 +345,6 @@ pub enum EdgeAppCommands {
/// Path to the directory with the manifest. If not specified CLI will use the current working directory.
#[arg(short, long)]
path: Option<String>,

/// Edge App id. If not specified CLI will use the id from the manifest.
#[arg(short, long)]
app_id: Option<String>,
},
/// Validates Edge App manifest file
Validate {
Expand Down Expand Up @@ -394,10 +382,6 @@ pub enum EdgeAppSettingsCommands {
pub enum EdgeAppInstanceCommands {
/// Lists Edge App instances.
List {
/// Edge app id. If not specified CLI will use the id from the manifest.
#[arg(short, long)]
app_id: Option<String>,

/// Path to the directory with the manifest. If not specified CLI will use the current working directory.
#[arg(short, long)]
path: Option<String>,
Expand All @@ -408,10 +392,6 @@ pub enum EdgeAppInstanceCommands {
},
/// Creates Edge App instance.
Create {
/// Edge app id. If not specified CLI will use the id from the manifest.
#[arg(short, long)]
app_id: Option<String>,

/// Name of the Edge App instance.
#[arg(short, long)]
name: Option<String>,
Expand Down Expand Up @@ -867,22 +847,19 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
}
EdgeAppCommands::Deploy {
path,
app_id,
delete_missing_settings,
} => {
match edge_app_command.deploy(path.clone(), app_id.clone(), *delete_missing_settings) {
Ok(revision) => {
println!(
"Edge app successfully deployed. Revision: {revision}.",
revision = revision
);
}
Err(e) => {
eprintln!("Failed to upload edge app: {e}.");
std::process::exit(1);
}
} => match edge_app_command.deploy(path.clone(), *delete_missing_settings) {
Ok(revision) => {
println!(
"Edge app successfully deployed. Revision: {revision}.",
revision = revision
);
}
}
Err(e) => {
eprintln!("Failed to upload edge app: {e}.");
std::process::exit(1);
}
},
EdgeAppCommands::Setting(command) => match command {
EdgeAppSettingsCommands::List { path, json } => {
let actual_installation_id =
Expand Down Expand Up @@ -910,8 +887,8 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
}
}
},
EdgeAppCommands::Delete { path, app_id } => {
let actual_app_id = match edge_app_command.get_actual_app_id(app_id, path) {
EdgeAppCommands::Delete { path } => {
let actual_app_id = match edge_app_command.get_app_id(path.clone()) {
Ok(id) => id,
Err(e) => {
error!("Error calling delete Edge App: {}", e);
Expand All @@ -937,17 +914,15 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
Ok(()) => {
println!("Edge App Deletion in Progress.\nRequest to delete the Edge App has been received and is now being processed. The deletion is marked for asynchronous handling, so it won't happen instantly.");
// If the user didn't specify an app id, we need to clear it from the manifest
if app_id.is_none() {
match edge_app_command
.clear_app_id(transform_edge_app_path_to_manifest(path).as_path())
{
Ok(()) => {
println!("App id cleared from manifest.");
}
Err(e) => {
error!("Error occurred while clearing manifest: {}", e);
std::process::exit(1);
}
match edge_app_command
.clear_app_id(transform_edge_app_path_to_manifest(path).as_path())
{
Ok(()) => {
println!("App id cleared from manifest.");
}
Err(e) => {
error!("Error occurred while clearing manifest: {}", e);
std::process::exit(1);
}
}
std::process::exit(0);
Expand All @@ -958,8 +933,8 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
}
}
}
EdgeAppCommands::Rename { path, app_id, name } => {
let actual_app_id = match edge_app_command.get_actual_app_id(app_id, path) {
EdgeAppCommands::Rename { path, name } => {
let actual_app_id = match edge_app_command.get_app_id(path.clone()) {
Ok(id) => id,
Err(e) => {
error!("Error calling delete Edge App: {}", e);
Expand Down Expand Up @@ -1023,8 +998,8 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
}
}
EdgeAppCommands::Instance(command) => match command {
EdgeAppInstanceCommands::List { app_id, path, json } => {
let actual_app_id = match edge_app_command.get_actual_app_id(app_id, path) {
EdgeAppInstanceCommands::List { path, json } => {
let actual_app_id = match edge_app_command.get_app_id(path.clone()) {
Ok(id) => id,
Err(e) => {
error!("Error calling list instances: {}", e);
Expand All @@ -1036,8 +1011,8 @@ pub fn handle_cli_edge_app_command(command: &EdgeAppCommands) {
json,
);
}
EdgeAppInstanceCommands::Create { app_id, path, name } => {
let actual_app_id = match edge_app_command.get_actual_app_id(app_id, path) {
EdgeAppInstanceCommands::Create { path, name } => {
let actual_app_id = match edge_app_command.get_app_id(path.clone()) {
Ok(id) => id,
Err(e) => {
error!("Error calling create instance: {}", e);
Expand Down
32 changes: 11 additions & 21 deletions src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,40 +189,32 @@ impl EdgeAppCommand {
pub fn deploy(
self,
path: Option<String>,
app_id: Option<String>,
delete_missing_settings: Option<bool>,
) -> Result<u32, CommandError> {
let manifest_path = transform_edge_app_path_to_manifest(&path);

EdgeAppManifest::ensure_manifest_is_valid(&manifest_path)?;
let mut manifest = EdgeAppManifest::new(&manifest_path)?;

Check failure on line 197 in src/commands/edge_app.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

error: variable does not need to be mutable --> src/commands/edge_app.rs:197:13 | 197 | let mut manifest = EdgeAppManifest::new(&manifest_path)?; | ----^^^^^^^^ | | | help: remove this `mut` | = note: `-D unused-mut` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_mut)]`

// override app_id if user passed it
if let Some(id) = app_id {
if id.is_empty() {
return Err(CommandError::EmptyAppId);
}
manifest.id = Some(id);
}
let actual_app_id = match manifest.id {
Some(ref id) => id,
None => return Err(CommandError::MissingAppId),
let actual_app_id = match self.get_app_id(path.clone()) {
Ok(id) => id,
Err(_) => return Err(CommandError::MissingAppId),
};

let version_metadata_changed =
self.detect_version_metadata_changes(actual_app_id, &manifest)?;
self.detect_version_metadata_changes(&actual_app_id, &manifest)?;

let edge_app_dir = manifest_path.parent().ok_or(CommandError::MissingField)?;

let local_files = collect_paths_for_upload(edge_app_dir)?;
ensure_edge_app_has_all_necessary_files(&local_files)?;

let revision = match self.get_latest_revision(actual_app_id)? {
let revision = match self.get_latest_revision(&actual_app_id)? {
Some(revision) => revision.revision,
None => 0,
};

let remote_files = self.get_version_asset_signatures(actual_app_id, revision)?;
let remote_files = self.get_version_asset_signatures(&actual_app_id, revision)?;
let changed_files = detect_changed_files(&local_files, &remote_files)?;
debug!("Changed files: {:?}", &changed_files);

Expand All @@ -247,7 +239,7 @@ impl EdgeAppCommand {

let file_tree = generate_file_tree(&local_files, edge_app_dir);

let old_file_tree = self.get_file_tree(actual_app_id, revision);
let old_file_tree = self.get_file_tree(&actual_app_id, revision);

let file_tree_changed = match old_file_tree {
Ok(tree) => file_tree != tree,
Expand All @@ -266,15 +258,15 @@ impl EdgeAppCommand {
let revision =
self.create_version(&manifest, generate_file_tree(&local_files, edge_app_dir))?;

self.upload_changed_files(edge_app_dir, actual_app_id, revision, &changed_files)?;
self.upload_changed_files(edge_app_dir, &actual_app_id, revision, &changed_files)?;
debug!("Files uploaded");

self.ensure_assets_processing_finished(actual_app_id, revision)?;
self.ensure_assets_processing_finished(&actual_app_id, revision)?;
// now we freeze it by publishing it
self.publish(actual_app_id, revision)?;
self.publish(&actual_app_id, revision)?;
debug!("Edge app published.");

self.promote_version(actual_app_id, revision, "stable")?;
self.promote_version(&actual_app_id, revision, "stable")?;

Ok(revision)
}
Expand Down Expand Up @@ -2805,7 +2797,6 @@ mod tests {

let result = command.deploy(
Some(temp_dir.path().to_str().unwrap().to_string()),
None,
Some(true),
);

Expand Down Expand Up @@ -3377,7 +3368,6 @@ mod tests {
let command = EdgeAppCommand::new(authentication);
let result = command.deploy(
Some(temp_dir.path().to_str().unwrap().to_string()),
None,
Some(true),
);

Expand Down

0 comments on commit 6052f3a

Please sign in to comment.