Skip to content

Commit

Permalink
refactor: rename manifest to config
Browse files Browse the repository at this point in the history
Because `arx.kdl` is essentially a config file, and manifest has a different
meaning and purpose.
  • Loading branch information
norskeld committed Mar 10, 2024
1 parent c6faf4a commit 426d7d1
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/actions/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
use unindent::Unindent;

use crate::actions::{State, Value};
use crate::manifest::actions::*;
use crate::config::actions::*;
use crate::path::{PathClean, Traverser};
use crate::spinner::Spinner;

Expand Down
18 changes: 9 additions & 9 deletions src/actions/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use miette::Diagnostic;
use thiserror::Error;
use tokio::fs;

use crate::manifest::{ActionSingle, ActionSuite, Actions, Manifest};
use crate::config::{ActionSingle, ActionSuite, Actions, Config};

#[derive(Debug, Diagnostic, Error)]
pub enum ExecutorError {
Expand Down Expand Up @@ -60,27 +60,27 @@ impl Default for State {
/// An executor.
#[derive(Debug)]
pub struct Executor {
/// The manifest to use for execution.
manifest: Manifest,
/// The config to use for execution.
config: Config,
}

impl Executor {
/// Create a new executor.
pub fn new(manifest: Manifest) -> Self {
Self { manifest }
pub fn new(config: Config) -> Self {
Self { config }
}

/// Execute the actions.
pub async fn execute(&self) -> miette::Result<()> {
match &self.manifest.actions {
match &self.config.actions {
| Actions::Suite(suites) => self.suite(suites).await?,
| Actions::Flat(actions) => self.flat(actions).await?,
| Actions::Empty => println!("No actions found."),
};

// Delete the config file if needed.
if self.manifest.options.delete {
fs::remove_file(&self.manifest.config)
if self.config.options.delete {
fs::remove_file(&self.config.config)
.await
.map_err(|source| {
ExecutorError::Io {
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Executor {

/// Execute a single action.
async fn single(&self, action: &ActionSingle, state: &mut State) -> miette::Result<()> {
let root = &self.manifest.root;
let root = &self.config.root;

match action {
| ActionSingle::Copy(action) => action.execute(root).await,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use inquire::ui::{Color, RenderConfig, StyleSheet, Styled};
use inquire::{Confirm, Editor, InquireError, Select, Text};

use crate::actions::{State, Value};
use crate::manifest::prompts;
use crate::config::prompts;

/// Helper struct holding useful static methods.
struct Inquirer;
Expand Down
40 changes: 20 additions & 20 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miette::Diagnostic;
use thiserror::Error;

use crate::actions::Executor;
use crate::manifest::{Manifest, ManifestOptionsOverrides};
use crate::config::{Config, ConfigOptionsOverrides};
use crate::repository::{LocalRepository, RemoteRepository};
use crate::unpacker::Unpacker;

Expand Down Expand Up @@ -88,20 +88,20 @@ impl App {
)
}))?;

// Load the manifest.
let manifest = match self.cli.command {
// Load the config.
let config = match self.cli.command {
| BaseCommand::Remote { src, path, meta, delete } => {
let options = ManifestOptionsOverrides { delete };
let options = ConfigOptionsOverrides { delete };
Self::remote(src, path, meta, options).await?
},
| BaseCommand::Local { src, path, meta, delete } => {
let options = ManifestOptionsOverrides { delete };
let options = ConfigOptionsOverrides { delete };
Self::local(src, path, meta, options).await?
},
};

// Create executor and kick off execution.
let executor = Executor::new(manifest);
let executor = Executor::new(config);
executor.execute().await?;

Ok(())
Expand All @@ -112,8 +112,8 @@ impl App {
src: String,
path: Option<String>,
meta: Option<String>,
overrides: ManifestOptionsOverrides,
) -> miette::Result<Manifest> {
overrides: ConfigOptionsOverrides,
) -> miette::Result<Config> {
// Parse repository.
let remote = RemoteRepository::new(src, meta)?;

Expand All @@ -135,22 +135,22 @@ impl App {
let unpacker = Unpacker::new(tarball);
unpacker.unpack_to(&destination)?;

// Now we need to read the manifest (if it is present).
let mut manifest = Manifest::new(&destination);
// Now we need to read the config (if it is present).
let mut config = Config::new(&destination);

manifest.load()?;
manifest.override_with(overrides);
config.load()?;
config.override_with(overrides);

Ok(manifest)
Ok(config)
}

/// Preparation flow for local repositories.
async fn local(
src: String,
path: Option<String>,
meta: Option<String>,
overrides: ManifestOptionsOverrides,
) -> miette::Result<Manifest> {
overrides: ConfigOptionsOverrides,
) -> miette::Result<Config> {
// Create repository.
let local = LocalRepository::new(src, meta);

Expand Down Expand Up @@ -196,13 +196,13 @@ impl App {
println!("{}", "~ Removed inner .git directory\n".dim());
}

// Now we need to read the manifest (if it is present).
let mut manifest = Manifest::new(&destination);
// Now we need to read the config (if it is present).
let mut config = Config::new(&destination);

manifest.load()?;
manifest.override_with(overrides);
config.load()?;
config.override_with(overrides);

Ok(manifest)
Ok(config)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/manifest/actions.rs → src/config/actions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use crate::manifest::prompts::*;
use crate::config::prompts::*;

/// Copies a file or directory. Glob-friendly. Overwrites by default.
#[derive(Debug)]
Expand Down
Loading

0 comments on commit 426d7d1

Please sign in to comment.