Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

om init: Upstream params, and support arbitrary flake as argument #281

Merged
merged 5 commits into from
Sep 19, 2024
Merged
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
11 changes: 5 additions & 6 deletions crates/omnix-cli/src/command/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashMap, path::PathBuf, str::FromStr};

use clap::Parser;
use nix_rs::flake::url::FlakeUrl;
use serde_json::Value;

/// Initialize a new flake project
Expand All @@ -10,12 +11,10 @@ pub struct InitCommand {
#[arg(short = 'o', long = "output")]
path: PathBuf,

/// The name of the template to use
/// The flake from which to initialize the template to use
///
/// If not passed, the user will presented with a list of templates to choose from.
///
/// In future, this will support arbitrary URLs. For now, we only support builtin templates.
template: Option<String>,
/// Defaults to builtin registry of flake templates.
flake: Option<FlakeUrl>,

/// Parameter values to use for the template by default.
#[arg(long = "params")]
Expand All @@ -30,7 +29,7 @@ impl InitCommand {
pub async fn run(&self) -> anyhow::Result<()> {
omnix_init::core::initialize_template(
&self.path,
self.template.clone(),
self.flake.clone(),
&self.params.clone().unwrap_or_default().0,
self.non_interactive,
)
Expand Down
11 changes: 6 additions & 5 deletions crates/omnix-cli/tests/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::Path;
use crate::command::core::om;
use assert_cmd::Command;
use nix_rs::{command::NixCmd, flake::url::FlakeUrl};
use omnix_init::config::BUILTIN_REGISTRY;
use predicates::str::contains;

/// `om init` runs and successfully initializes a template
Expand All @@ -17,7 +18,7 @@ async fn om_init() -> anyhow::Result<()> {
fn om_init_tests() -> Vec<OmInitTest> {
vec![
OmInitTest {
template_name: "haskell-template",
template_name: BUILTIN_REGISTRY.with_attr("haskell-template"),
default_params: r#"{"package-name": "foo", "author": "John", "vscode": false }"#,
asserts: Asserts {
out_dir: PathAsserts {
Expand All @@ -29,7 +30,7 @@ fn om_init_tests() -> Vec<OmInitTest> {
},
},
OmInitTest {
template_name: "rust-nix-template",
template_name: BUILTIN_REGISTRY.with_attr("rust-nix-template"),
default_params: r#"{"package-name": "qux", "author": "John", "author-email": "john@example.com" }"#,
asserts: Asserts {
out_dir: PathAsserts {
Expand All @@ -46,7 +47,7 @@ fn om_init_tests() -> Vec<OmInitTest> {
},
},
OmInitTest {
template_name: "nix-dev-home",
template_name: BUILTIN_REGISTRY.with_attr("nix-dev-home"),
default_params: r#"{"username": "john", "git-email": "jon@ex.com", "git-name": "John", "neovim": true }"#,
asserts: Asserts {
out_dir: PathAsserts {
Expand All @@ -66,7 +67,7 @@ fn om_init_tests() -> Vec<OmInitTest> {
/// A test for a single template
struct OmInitTest {
/// The template name to pass to `om init`
template_name: &'static str,
template_name: FlakeUrl,
/// The --default-params to pass to `om init`
default_params: &'static str,
/// Various assertions to make after running `om init`
Expand All @@ -82,7 +83,7 @@ impl OmInitTest {
"init",
"-o",
&temp_dir.to_string_lossy(),
self.template_name,
&self.template_name,
"--non-interactive",
"--params",
self.default_params,
Expand Down
Loading