Skip to content

Commit

Permalink
Merge pull request #44 from tweag/nixtract-options
Browse files Browse the repository at this point in the history
feat: add functions to Backend trait to set options
  • Loading branch information
Erin van der Veen authored Apr 8, 2024
2 parents ec1fa87 + ef28f38 commit 5f7834a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#34](https://github.com/tweag/genealogos/pull/34) implements a web-based GUI for Genealogos
- [#36](https://github.com/tweag/genealogos/pull/36) include nixtract's new narinfo information
- [#38](https://github.com/tweag/genealogos/pull/38) display nixtract's status information when running
- [#44](https://github.com/tweag/genealogos/pull/44) adds two functions to the `Backend` trait to set options

### Changed
- [#41](https://github.com/tweag/genealogos/pull/41) reworked the Genealogos fronend, paving the way for supporting other bom formats
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ nixtract --target-attribute-path hello /tmp/out && genealogos /tmp/out

For more `nixtract` arguments, see `nixtract --help`.

Setting backend options:
Any type that implements the `Backend` must have a way to include nar info and only include runtime options.
Genealogos will forward `--include-narinfo` and `--runtime-only` to the backend.
```fish
genealogos --flake-ref nixpkgs --attribute-path hello --include-narinfo --runtime-only
```

For a full set of options, see:
```fish
genealogos --help
Expand Down
15 changes: 14 additions & 1 deletion genealogos-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ struct Args {
#[arg(long, default_value_t)]
backend: args::BackendArg,

/// Attempt to include narinfo data in the bom
#[arg(long, default_value_t)]
include_narinfo: bool,

/// Attempt to only include runtime dependencies in the bom
#[arg(long, default_value_t)]
runtime_only: bool,

/// Optional bom specification to output
#[arg(long, default_value_t)]
bom: args::BomArg,
Expand All @@ -54,7 +62,12 @@ fn main() -> Result<()> {
};

// Initialize the backend and get access to the status update messages
let (backend, handle) = *args.backend.get_backend()?;
let (mut backend, handle) = *args.backend.get_backend()?;

// Set backend options
backend.include_narinfo(args.include_narinfo);
backend.runtime_only(args.runtime_only);

let messages = handle.messages()?;

// Initialize the frontend (bom)
Expand Down
30 changes: 30 additions & 0 deletions genealogos/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ pub trait Backend {
/// A `Result` which is `Ok` if the conversion succeeded, and
///`crate:error::Error` otherwise.
fn to_model_from_lines(&self, lines: impl Iterator<Item = impl AsRef<str>>) -> Result<Model>;

/// Informs the backend to (from now on) attempt to fetch the narinfo for each derivation.
///
/// # Arguments
///
/// * `fetch` - A boolean indicating whether to fetch the narinfo for each derivation or not.
///
/// # Examples
///
/// ```
/// use genealogos::backend::Backend;
/// let mut backend = genealogos::backend::nixtract_backend::Nixtract::new_without_handle();
/// backend.include_narinfo(true);
/// ```
fn include_narinfo(&mut self, include: bool);

/// Informs the backend to (from now on) only include runtime dependencies in the model.
///
/// # Arguments
///
/// * `runtime_only` - A boolean indicating whether to include only runtime dependencies or not.
///
/// # Examples
///
/// ```
/// use genealogos::backend::Backend;
/// let mut backend = genealogos::backend::nixtract_backend::Nixtract::new_without_handle();
/// backend.runtime_only(true);
/// ```
fn runtime_only(&mut self, runtime_only: bool);
}

/// If a backend was created with a `BackendHandle`, it can be queried for status updates.
Expand Down
8 changes: 8 additions & 0 deletions genealogos/src/backend/nixtract_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ impl crate::backend::Backend for Nixtract {

Ok(model)
}

fn include_narinfo(&mut self, include: bool) {
self.config.include_nar_info = include;
}

fn runtime_only(&mut self, runtime_only: bool) {
self.config.runtime_only = runtime_only
}
}

impl super::BackendHandle for NixtractHandle {
Expand Down

0 comments on commit 5f7834a

Please # to comment.