Skip to content

Commit 694d1bd

Browse files
committed
feat!: Add rebuild and remove library
- Add manifest info printing to identify manifest more easily. - Rebuild cleans before building - The lib and CLI were already too tightly coupled - The lib didn't have any reason to exist
1 parent 8468508 commit 694d1bd

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@ nix = { version = "0.30.1", features = ["process", "signal", "user"] }
2727
[[bin]]
2828
name = "flatplay"
2929
path = "src/main.rs"
30-
31-
[lib]
32-
name = "flatplay"
33-
path = "src/lib.rs"

src/lib.rs renamed to src/flatpak_manager.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
mod build_dirs;
2-
mod command;
3-
mod manifest;
4-
pub mod process;
5-
pub mod state;
6-
mod utils;
7-
81
use std::fs;
92
use std::path::PathBuf;
103

114
use anyhow::Result;
125
use colored::*;
13-
use command::{flatpak_builder, run_command};
146
use dialoguer::{Select, theme::ColorfulTheme};
157
use nix::unistd::geteuid;
168

179
use crate::build_dirs::BuildDirs;
10+
use crate::command::{flatpak_builder, run_command};
1811
use crate::manifest::{Manifest, Module, find_manifests_in_path};
19-
use crate::process::kill_process_group;
2012
use crate::state::State;
2113
use crate::utils::{get_a11y_bus_args, get_host_env};
2214

@@ -46,16 +38,25 @@ impl<'a> FlatpakManager<'a> {
4638
fn auto_select_manifest(&mut self) -> Result<bool> {
4739
let manifests = self.find_manifests()?;
4840
if let Some(manifest_path) = manifests.first() {
49-
self.state.active_manifest = Some(manifest_path.clone());
50-
self.state.save()?;
5141
println!("{} {:?}", "Auto-selected manifest:".green(), manifest_path);
52-
self.manifest = Some(Manifest::from_file(manifest_path)?);
42+
let manifest = Manifest::from_file(manifest_path)?;
43+
self.set_active_manifest(manifest_path.clone(), Some(manifest))?;
5344
Ok(true)
5445
} else {
5546
Ok(false)
5647
}
5748
}
5849

50+
fn print_manifest_info(&self) {
51+
if let Some(manifest) = &self.manifest {
52+
println!("{}", "Manifest Info:".bold().blue());
53+
println!(" App ID: {}", manifest.id.yellow());
54+
println!(" SDK: {}", manifest.sdk.cyan());
55+
println!(" Runtime: {}", manifest.runtime.cyan());
56+
println!(" Runtime Version: {}", manifest.runtime_version.cyan());
57+
}
58+
}
59+
5960
pub fn new(state: &'a mut State) -> Result<Self> {
6061
let manifest = if let Some(path) = &state.active_manifest {
6162
Some(Manifest::from_file(path)?)
@@ -71,6 +72,12 @@ impl<'a> FlatpakManager<'a> {
7172
if manager.manifest.is_none() && !manager.auto_select_manifest()? {
7273
return Err(anyhow::anyhow!("No manifest found."));
7374
}
75+
76+
// Print manifest info when we have one
77+
if manager.manifest.is_some() {
78+
manager.print_manifest_info();
79+
}
80+
7481
manager.init()?;
7582
Ok(manager)
7683
}
@@ -335,15 +342,18 @@ impl<'a> FlatpakManager<'a> {
335342
self.state.save()
336343
}
337344

345+
pub fn rebuild(&mut self) -> Result<()> {
346+
println!("{}", "Rebuilding application...".bold());
347+
self.clean()?;
348+
self.build()
349+
}
350+
338351
pub fn build_and_run(&mut self) -> Result<()> {
352+
println!("{}", "Building and running application...".bold());
339353
self.build()?;
340354
self.run()
341355
}
342356

343-
pub fn stop(&mut self) -> Result<()> {
344-
kill_process_group(self.state)
345-
}
346-
347357
pub fn run(&self) -> Result<()> {
348358
if !self.state.application_built {
349359
println!(
@@ -572,6 +582,10 @@ impl<'a> FlatpakManager<'a> {
572582
if let Some(manifest) = manifest {
573583
self.manifest = Some(manifest);
574584
}
585+
586+
// Print manifest info
587+
self.print_manifest_info();
588+
575589
println!(
576590
"{} {:?}. You can now run `{}`.",
577591
"Selected manifest:".green(),

src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ use clap::{CommandFactory, Parser, Subcommand};
66
use colored::*;
77
use nix::unistd::{getpid, setpgid};
88

9-
use flatplay::FlatpakManager;
10-
use flatplay::process::{is_process_running, kill_process_group};
11-
use flatplay::state::State;
9+
mod build_dirs;
10+
mod command;
11+
mod flatpak_manager;
12+
mod manifest;
13+
mod process;
14+
mod state;
15+
mod utils;
16+
17+
use flatpak_manager::FlatpakManager;
18+
use process::{is_process_running, kill_process_group};
19+
use state::State;
1220

1321
#[derive(Parser)]
1422
#[command(author, version, about, long_about = None)]
@@ -23,6 +31,8 @@ enum Commands {
2331
Build,
2432
/// Build or rebuild the application then run it
2533
BuildAndRun,
34+
/// Clean the Flatpak repo directory and rebuild the application
35+
Rebuild,
2636
/// Stop the currently running task
2737
Stop,
2838
/// Run the application
@@ -149,6 +159,7 @@ fn main() {
149159

150160
Some(Commands::Build) => handle_command!(flatpak_manager.build()),
151161
Some(Commands::BuildAndRun) => handle_command!(flatpak_manager.build_and_run()),
162+
Some(Commands::Rebuild) => handle_command!(flatpak_manager.rebuild()),
152163
Some(Commands::Run) => handle_command!(flatpak_manager.run()),
153164
Some(Commands::UpdateDependencies) => {
154165
handle_command!(flatpak_manager.update_dependencies())

0 commit comments

Comments
 (0)