Skip to content

Commit

Permalink
cli: Get status code description from aklite CLI API (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Detsch <andre.detsch@foundries.io>
  • Loading branch information
detsch authored Sep 11, 2024
1 parent 78b1727 commit a6cd327
Showing 1 changed file with 2 additions and 94 deletions.
96 changes: 2 additions & 94 deletions src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,100 +17,8 @@
#define LOG_ERROR BOOST_LOG_TRIVIAL(error)

static void print_status(aklite::cli::StatusCode ret) {
switch (ret) {
case aklite::cli::StatusCode::Ok:
std::cout << "SUCCESS";
break;

// Possible return codes for check, pull and install commands
case aklite::cli::StatusCode::CheckinOkCached:
std::cout << "SUCCESS: Unable to fetch updated TUF metadata, but stored metadata is valid";
break;
case aklite::cli::StatusCode::CheckinFailure:
std::cout << "FAILURE: Failed to update TUF metadata";
break;
case aklite::cli::StatusCode::CheckinNoMatchingTargets:
std::cout << "FAILURE: There is no matching target for the device";
break;
case aklite::cli::StatusCode::CheckinNoTargetContent:
std::cout << "FAILURE: There is no target metadata in the local path";
break;
case aklite::cli::StatusCode::CheckinSecurityError:
std::cout << "FAILURE: Invalid TUF metadata";
break;
case aklite::cli::StatusCode::CheckinExpiredMetadata:
std::cout << "FAILURE: TUF metadata is expired";
break;
case aklite::cli::StatusCode::CheckinMetadataFetchFailure:
std::cout << "FAILURE: Unable to fetch TUF metadata";
break;
case aklite::cli::StatusCode::TufTargetNotFound:
std::cout << "FAILURE: Selected target not found";
break;

// Possible return codes for pull and install commands
case aklite::cli::StatusCode::InstallationInProgress:
std::cout << "FAILURE: Unable to pull/install: there is an installation that needs completion";
break;
case aklite::cli::StatusCode::DownloadFailure:
std::cout << "FAILURE: Unable to download target";
break;
case aklite::cli::StatusCode::DownloadFailureVerificationFailed:
std::cout << "FAILURE: Target downloaded but verification has failed";
break;
case aklite::cli::StatusCode::DownloadFailureNoSpace:
std::cout << "FAILURE: There is no enough free space to download the target";
break;
case aklite::cli::StatusCode::InstallAlreadyInstalled:
std::cout << "FAILURE: Selected target is already installed";
break;
case aklite::cli::StatusCode::InstallDowngradeAttempt:
// Should not hit this error, since force_downgrade is set to true
std::cout << "FAILURE: Attempted to install a previous version";
break;

// Possible return codes for install command
case aklite::cli::StatusCode::InstallAppsNeedFinalization:
std::cout << "SUCCESS: Execute `sotactl run` command to finalize installation";
break;
case aklite::cli::StatusCode::InstallNeedsRebootForBootFw:
std::cout << "FAILURE: Reboot is required before installing the target";
break;
case aklite::cli::StatusCode::InstallAppPullFailure:
std::cout << "FAILURE: Unable read target data, make sure it was pulled";
break;

// Possible return codes for install and run command
case aklite::cli::StatusCode::InstallNeedsReboot:
std::cout << "SUCCESS: Reboot to finalize installation";
break;
case aklite::cli::StatusCode::OkNeedsRebootForBootFw:
std::cout << "SUCCESS: Reboot to finalize bootloader installation";
break;
case aklite::cli::StatusCode::InstallRollbackNeedsReboot:
std::cout << "FAILURE: Installation failed, rollback initiated but requires reboot to finalize";
break;

// Possible return codes for run command
case aklite::cli::StatusCode::NoPendingInstallation:
std::cout << "FAILURE: No pending installation to run";
break;
case aklite::cli::StatusCode::InstallRollbackOk:
case aklite::cli::StatusCode::InstallOfflineRollbackOk:
std::cout << "FAILURE: Installation failed, rollback performed";
break;
case aklite::cli::StatusCode::InstallRollbackFailed:
std::cout << "FAILURE: Installation failed and rollback operation was not successful";
break;
case aklite::cli::StatusCode::UnknownError:
std::cout << "FAILURE: Unknown error";
break;

default:
std::cout << "FAILURE: Unexpected return code " << static_cast<int>(ret);
break;
}
std::cout << std::endl;
auto success_string = aklite::cli::IsSuccessCode(ret)? "SUCCESS" : "FAILURE";
std::cout << success_string << ": " << aklite::cli::StatusCodeDescription(ret) << std::endl;
}

static std::unique_ptr<AkliteClientExt> init_client(bool online_mode) {
Expand Down

0 comments on commit a6cd327

Please sign in to comment.