Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tockloader-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ fn get_subcommands() -> Vec<Command> {
.args(get_app_args())
.args(get_channel_args())
.arg_required_else_help(false),
Command::new("uninstall")
.about("Uninstall apps")
.arg(arg!(--"name" <APPNAME>).required(false))
.args(get_app_args())
.args(get_channel_args())
.arg_required_else_help(false),
]
}

Expand Down
90 changes: 75 additions & 15 deletions tockloader-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use anyhow::{Context, Result};
use clap::ArgMatches;
use cli::make_cli;
use known_boards::KnownBoardNames;
use tockloader_lib::attributes::app_attributes::AppOption;
use tockloader_lib::board_settings::BoardSettings;
use tockloader_lib::connection::{
Connection, ProbeRSConnection, ProbeTargetInfo, SerialConnection, SerialTargetInfo,
Expand All @@ -19,7 +20,7 @@ use tockloader_lib::known_boards::KnownBoard;
use tockloader_lib::tabs::tab::Tab;
use tockloader_lib::{
list_debug_probes, list_serial_ports, CommandEraseApps, CommandInfo, CommandInstall,
CommandList,
CommandList, CommandUninstall,
};

fn get_serial_target_info(user_options: &ArgMatches) -> SerialTargetInfo {
Expand Down Expand Up @@ -111,8 +112,12 @@ async fn open_connection(user_options: &ArgMatches) -> Result<TockloaderConnecti
.context("No device is connected.")?
};

let mut conn: TockloaderConnection =
SerialConnection::new(path, get_serial_target_info(user_options)).into();
let mut conn: TockloaderConnection = SerialConnection::new(
path,
get_serial_target_info(user_options),
get_board_settings(user_options),
)
.into();
conn.open()
.await
.context("Failed to open serial connection.")?;
Expand All @@ -124,8 +129,12 @@ async fn open_connection(user_options: &ArgMatches) -> Result<TockloaderConnecti
.prompt()
.context("No debug probe is connected.")?;

let mut conn: TockloaderConnection =
ProbeRSConnection::new(ans, get_probe_target_info(user_options)).into();
let mut conn: TockloaderConnection = ProbeRSConnection::new(
ans,
get_probe_target_info(user_options),
get_board_settings(user_options),
)
.into();

conn.open()
.await
Expand Down Expand Up @@ -199,19 +208,17 @@ async fn main() -> Result<()> {
cli::validate(&mut cmd, sub_matches);

let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

let app_details = conn.list(&settings).await.context("Failed to list apps.")?;
let app_details = conn.list().await.context("Failed to list apps.")?;

display::print_list(&app_details).await;
}
Some(("info", sub_matches)) => {
cli::validate(&mut cmd, sub_matches);
let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

let mut attributes = conn
.info(&settings)
.info()
.await
.context("Failed to get data from the board.")?;

Expand All @@ -223,20 +230,73 @@ async fn main() -> Result<()> {
.context("Failed to use provided tab file.")?;

let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

conn.install_app(&settings, tab_file)
conn.install_app(tab_file)
.await
.context("Failed to install app.")?;
}
Some(("erase-apps", sub_matches)) => {
cli::validate(&mut cmd, sub_matches);
let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

conn.erase_apps(&settings)
.await
.context("Failed to erase apps.")?;
conn.erase_apps().await.context("Failed to erase apps.")?;
}
Some(("uninstall", sub_matches)) => {
cli::validate(&mut cmd, sub_matches);
let mut conn = open_connection(sub_matches).await?;
let installed_apps = conn.list().await.context("Failed to list apps.")?;
let app_name = sub_matches.get_one::<String>("name").map(String::as_str);

if installed_apps.is_empty() {
println!("No apps installed");
return Ok(());
}
match app_name {
Some(app_name) => {
installed_apps
.iter()
.find(|iter| iter.tbf_header.get_package_name().unwrap_or("") == app_name)
.expect("Specified app is not installed");
conn.uninstall_app(Some(app_name.to_string()), None)
.await
.context("Failed to uninstall app.")?;
}
None => loop {
let mut options: Vec<AppOption> = installed_apps
.iter()
.enumerate()
.map(|(i, app)| AppOption { index: i + 1, app })
.collect();

// Delete all option
options.insert(
0,
AppOption {
index: 0,
app: &installed_apps[0],
},
);
let selected =
inquire::Select::new("Which app do you want to uninstall?", options)
.prompt()
.context("No apps installed")
.unwrap();

if inquire::Select::new(
format!("You chose {selected}",).as_str(),
["Cancel", "Confirm"].to_vec(),
)
.prompt()
.unwrap()
== "Confirm"
{
conn.uninstall_app(None, Some(selected.index))
.await
.context("Failed to uninstall app")?;
break;
}
},
}
}
_ => {
println!("Could not run the provided subcommand.");
Expand Down
5 changes: 3 additions & 2 deletions tockloader-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ edition = "2021"

[dependencies]
tokio = { version = "1.32.0", features = ["full"] }
tokio-serial = {version = "5.4.4", features = ["libudev"]}
tokio-serial = { version = "5.4.4", features = ["libudev"] }
probe-rs = "0.24.0"
tbf-parser = { path = "../tbf-parser"}
tbf-parser = { path = "../tbf-parser" }
utf8-decode = "1.0.1"
byteorder = "1.5.0"
tar = "0.4.41"
Expand All @@ -21,3 +21,4 @@ serde = { version = "1.0.210", features = ["derive"] }
thiserror = "1.0.63"
async-trait = "0.1.88"
log = "0.4.27"
itertools = "0.14.0"
Loading
Loading