feat: add --generate-config mode to output default config
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -63,6 +63,10 @@ pub struct ModeArgs {
|
|||||||
#[arg(help("Start REST HTTP server"))]
|
#[arg(help("Start REST HTTP server"))]
|
||||||
pub server: bool,
|
pub server: bool,
|
||||||
|
|
||||||
|
#[arg(group("mode"), help_heading("Mode Options"), long, conflicts_with_all(["save", "get", "diff", "list", "delete", "info", "status", "server"]))]
|
||||||
|
#[arg(help("Generate default configuration and output to stdout"))]
|
||||||
|
pub generate_config: bool,
|
||||||
|
|
||||||
#[arg(help_heading("Server Options"), long, env("KEEP_SERVER_ADDRESS"))]
|
#[arg(help_heading("Server Options"), long, env("KEEP_SERVER_ADDRESS"))]
|
||||||
#[arg(help("Server address to bind to"))]
|
#[arg(help("Server address to bind to"))]
|
||||||
pub server_address: Option<String>,
|
pub server_address: Option<String>,
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ fn main() -> Result<(), Error> {
|
|||||||
Info,
|
Info,
|
||||||
Status,
|
Status,
|
||||||
Server,
|
Server,
|
||||||
|
GenerateConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut mode: KeepModes = KeepModes::Unknown;
|
let mut mode: KeepModes = KeepModes::Unknown;
|
||||||
@@ -105,6 +106,8 @@ fn main() -> Result<(), Error> {
|
|||||||
mode = KeepModes::Status;
|
mode = KeepModes::Status;
|
||||||
} else if args.mode.server {
|
} else if args.mode.server {
|
||||||
mode = KeepModes::Server;
|
mode = KeepModes::Server;
|
||||||
|
} else if args.mode.generate_config {
|
||||||
|
mode = KeepModes::GenerateConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode == KeepModes::Unknown {
|
if mode == KeepModes::Unknown {
|
||||||
@@ -174,6 +177,7 @@ fn main() -> Result<(), Error> {
|
|||||||
KeepModes::Info => modes::info::mode_info(&mut cmd, &settings, ids, tags, &mut conn, data_path),
|
KeepModes::Info => modes::info::mode_info(&mut cmd, &settings, ids, tags, &mut conn, data_path),
|
||||||
KeepModes::Status => modes::status::mode_status(&mut cmd, &settings, data_path, db_path),
|
KeepModes::Status => modes::status::mode_status(&mut cmd, &settings, data_path, db_path),
|
||||||
KeepModes::Server => modes::server::mode_server(&mut cmd, &settings, &mut conn, data_path),
|
KeepModes::Server => modes::server::mode_server(&mut cmd, &settings, &mut conn, data_path),
|
||||||
|
KeepModes::GenerateConfig => modes::generate_config::mode_generate_config(&mut cmd, &settings),
|
||||||
KeepModes::Unknown => unreachable!(),
|
KeepModes::Unknown => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use clap::Command;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_yaml;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct DefaultConfig {
|
||||||
|
dir: Option<String>,
|
||||||
|
list_format: Vec<String>,
|
||||||
|
human_readable: bool,
|
||||||
|
output_format: Option<String>,
|
||||||
|
quiet: bool,
|
||||||
|
server: Option<ServerConfig>,
|
||||||
|
compression_plugins: Vec<String>,
|
||||||
|
meta_plugins: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct ServerConfig {
|
||||||
|
address: Option<String>,
|
||||||
|
port: Option<u16>,
|
||||||
|
password_file: Option<String>,
|
||||||
|
password: Option<String>,
|
||||||
|
password_hash: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mode_generate_config(_cmd: &mut Command, _settings: &crate::config::Settings) -> Result<()> {
|
||||||
|
// Create a default configuration
|
||||||
|
let default_config = DefaultConfig {
|
||||||
|
dir: Some("~/.local/share/keep".to_string()),
|
||||||
|
list_format: vec![
|
||||||
|
"id".to_string(),
|
||||||
|
"time".to_string(),
|
||||||
|
"size".to_string(),
|
||||||
|
"tags".to_string(),
|
||||||
|
"meta:hostname".to_string(),
|
||||||
|
],
|
||||||
|
human_readable: false,
|
||||||
|
output_format: Some("table".to_string()),
|
||||||
|
quiet: false,
|
||||||
|
server: Some(ServerConfig {
|
||||||
|
address: Some("127.0.0.1".to_string()),
|
||||||
|
port: Some(8080),
|
||||||
|
password_file: None,
|
||||||
|
password: None,
|
||||||
|
password_hash: None,
|
||||||
|
}),
|
||||||
|
compression_plugins: vec![],
|
||||||
|
meta_plugins: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Serialize to YAML and print to stdout
|
||||||
|
let yaml = serde_yaml::to_string(&default_config)?;
|
||||||
|
println!("{}", yaml);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod diff;
|
pub mod diff;
|
||||||
|
pub mod generate_config;
|
||||||
pub mod get;
|
pub mod get;
|
||||||
pub mod info;
|
pub mod info;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
|
|||||||
Reference in New Issue
Block a user