aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs94
1 files changed, 78 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 08c88f5..7f5bcdc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,6 +21,7 @@ pub(crate) mod images;
pub(crate) mod process;
pub(crate) mod project;
pub(crate) mod release;
+pub(crate) mod render;
use std::path::{Path, PathBuf};
use std::process::ExitCode;
@@ -51,13 +52,22 @@ struct Cli {
enum Action {
#[command(about = "Run the experimental local chat or initialize its single .env")]
Chat {
- #[arg(long)]
+ #[arg(long, conflicts_with_all = ["reset_owner", "owner_fingerprint"])]
init: bool,
+ #[arg(
+ long,
+ value_name = "FINGERPRINT",
+ conflicts_with = "owner_fingerprint",
+ help = "Permanently clear owner registration and chat history after key loss"
+ )]
+ reset_owner: Option<String>,
+ #[arg(long, help = "Print the registered owner's public fingerprint")]
+ owner_fingerprint: bool,
},
#[command(about = "Start the local development services")]
Dev {
- #[arg(long, default_value_t = 8080)]
- port: u16,
+ #[arg(long)]
+ port: Option<u16>,
},
#[command(about = "Start or update services in the selected mode")]
Up {
@@ -70,6 +80,15 @@ enum Action {
#[arg(long)]
online: bool,
},
+ #[command(
+ about = "Render public Caddy, website, and cgit configuration without starting services"
+ )]
+ Config {
+ #[arg(long)]
+ production: bool,
+ #[arg(long)]
+ port: Option<u16>,
+ },
#[command(about = "Show service status")]
Status,
#[command(about = "Stop services while retaining data")]
@@ -79,8 +98,8 @@ enum Action {
destination: Option<PathBuf>,
#[arg(long)]
include_images: bool,
- #[arg(long, default_value = archive::RECIPIENT)]
- recipient: String,
+ #[arg(long)]
+ recipient: Option<String>,
#[arg(long)]
key: Option<PathBuf>,
},
@@ -132,22 +151,23 @@ fn execute(arguments: Cli) -> Result<()> {
return archive::restore(&absolute(archive)?, &absolute(destination)?);
}
let project = Project::discover(arguments.root.as_deref())?;
- if let Action::Chat { init } = arguments.command {
- let mut command = project.command("cargo")?;
- command
- .args(["run", "--locked", "-p", "stack-chat-server", "--", "--root"])
- .arg(&project.root);
- if init {
- command.arg("--init");
- }
- return process::run(&mut command);
+ if let Action::Chat {
+ init,
+ reset_owner,
+ owner_fingerprint,
+ } = arguments.command
+ {
+ return chat(&project, init, reset_owner.as_deref(), owner_fingerprint);
}
+
let _operation = project.lock()?;
match arguments.command {
Action::Dev { port } => {
let mut settings = project.settings()?;
settings.mode = Mode::Local;
- settings.port = port;
+ if let Some(selected_port) = port {
+ settings.port = selected_port;
+ }
images::prepare(&project, &mut settings)?;
project.up(&settings)
}
@@ -173,6 +193,23 @@ fn execute(arguments: Cli) -> Result<()> {
images::prepare(&project, &mut settings)?;
project.up(&settings)
}
+ Action::Config { production, port } => {
+ let mut settings = project.settings()?;
+ settings.mode = if production {
+ Mode::Production
+ } else {
+ Mode::Local
+ };
+ if let Some(selected_port) = port {
+ settings.port = selected_port;
+ }
+ stack_config::initialize_public(&project.root)?;
+ render::prepare(&project, &settings)?;
+ process::line(format_args!(
+ "Public configuration: {}",
+ render::directory(&project, &settings).display()
+ ))
+ }
Action::Status => project.status(&project.settings()?),
Action::Down => project.down(&project.settings()?),
Action::Backup {
@@ -185,11 +222,14 @@ fn execute(arguments: Cli) -> Result<()> {
|| Ok(project.root.join("var/exports")),
|path| absolute(&path),
)?;
+ let configuration = stack_config::Config::load(&project.root)?;
+ let selected_recipient =
+ recipient.unwrap_or(configuration.value("BACKUP_RECIPIENT")?.to_owned());
archive::backup(
&project,
&output,
include_images,
- &recipient,
+ &selected_recipient,
key.as_deref(),
)
}
@@ -206,6 +246,28 @@ fn execute(arguments: Cli) -> Result<()> {
}
}
+fn chat(
+ project: &Project,
+ init: bool,
+ reset_owner: Option<&str>,
+ owner_fingerprint: bool,
+) -> Result<()> {
+ let mut command = project.command("cargo")?;
+ command
+ .args(["run", "--locked", "-p", "stack-chat-server", "--", "--root"])
+ .arg(&project.root);
+ if init {
+ command.arg("--init");
+ }
+ if let Some(fingerprint) = reset_owner {
+ command.arg("--reset-owner").arg(fingerprint);
+ }
+ if owner_fingerprint {
+ command.arg("--owner-fingerprint");
+ }
+ process::run(&mut command)
+}
+
fn absolute(path: &Path) -> Result<PathBuf> {
Ok(if path.is_absolute() {
path.to_path_buf()