Skip to content

Commit

Permalink
refactor: format variants and imports to be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
norskeld committed Apr 7, 2024
1 parent b9f7433 commit 04be77c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/actions/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::process;
use crossterm::style::Stylize;
use inquire::formatter::StringFormatter;
use inquire::ui::{Color, RenderConfig, StyleSheet, Styled};
use inquire::{required, CustomType};
use inquire::{Confirm, Editor, InquireError, Select, Text};
use inquire::{Confirm, CustomType, Editor, InquireError, Select, Text};

use crate::actions::State;
use crate::config::prompts::*;
Expand Down Expand Up @@ -102,7 +101,7 @@ impl InputPrompt {
if let Some(default) = &self.default {
prompt = prompt.with_default(default);
} else {
prompt = prompt.with_validator(required!("This field is required."));
prompt = prompt.with_validator(inquire::required!("This field is required."));
}

match prompt.prompt() {
Expand Down
19 changes: 6 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub enum AppError {

#[derive(Debug, Default)]
pub struct AppState {
/// Whether to cleanup on failure or not.
/// Whether to clean up on failure or not.
pub cleanup: bool,
/// Cleanup path, will be set to the destination acquired after creating [RemoteRepository] or
/// Clean up path, will be set to the destination acquired after creating [RemoteRepository] or
/// [LocalRepository].
pub cleanup_path: Option<PathBuf>,
}
Expand All @@ -39,19 +39,15 @@ pub struct AppState {
pub struct Cli {
#[command(subcommand)]
pub command: BaseCommand,

/// Cleanup on failure. No-op if failed because target directory already exists.
/// Clean up on failure. No-op if failed because target directory already exists.
#[arg(global = true, short = 'C', long)]
cleanup: bool,

/// Delete arx config after scaffolding is complete.
#[arg(global = true, short, long)]
delete: Option<bool>,

/// Use cached template if available.
#[arg(global = true, short = 'c', long, default_value = "true")]
cache: bool,

/// Skip running actions.
#[arg(global = true, short, long)]
skip: bool,
Expand All @@ -64,24 +60,19 @@ pub enum BaseCommand {
Remote {
/// Repository to use for scaffolding.
src: String,

/// Directory to scaffold to.
path: Option<String>,

/// Scaffold from a specified ref (branch, tag, or commit).
#[arg(name = "REF", short = 'r', long = "ref")]
meta: Option<String>,
},

/// Scaffold from a local repository.
#[command(visible_alias = "l")]
Local {
/// Repository to use for scaffolding.
src: String,

/// Directory to scaffold to.
path: Option<String>,

/// Scaffold from a specified ref (branch, tag, or commit).
#[arg(name = "REF", short = 'r', long = "ref")]
meta: Option<String>,
Expand All @@ -90,7 +81,9 @@ pub enum BaseCommand {

#[derive(Debug)]
pub struct App {
/// Parsed CLI options and commands.
cli: Cli,
/// Current state of the application.
state: AppState,
}

Expand Down Expand Up @@ -276,7 +269,7 @@ impl App {
}
}

/// Cleanup on failure.
/// Clean up on failure.
pub fn cleanup(&self) -> miette::Result<()> {
if self.state.cleanup {
if let Some(destination) = &self.state.cleanup_path {
Expand Down
5 changes: 1 addition & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use std::fs;
use std::io;
use std::path::Path;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use base32::Alphabet;
use chrono::Utc;
Expand Down Expand Up @@ -37,11 +36,9 @@ pub enum CacheError {
#[source]
source: io::Error,
},

#[error(transparent)]
#[diagnostic(code(arx::cache::manifest::serialize))]
TomlSerialize(toml::ser::Error),

#[error(transparent)]
#[diagnostic(code(arx::cache::manifest::deserialize))]
TomlDeserialize(toml::de::Error),
Expand Down
5 changes: 3 additions & 2 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ pub enum ConfigError {
#[source]
source: io::Error,
},

#[error(transparent)]
#[diagnostic(transparent)]
Kdl(kdl::KdlError),

#[error("{0}")]
#[diagnostic(transparent)]
Diagnostic(Report),
Expand Down Expand Up @@ -88,8 +86,11 @@ pub struct ConfigOptionsOverrides {
/// ```
#[derive(Debug)]
pub enum Actions {
/// Suites of actions to run.
Suite(Vec<ActionSuite>),
/// Flat list of actions to run.
Flat(Vec<ActionSingle>),
/// No actions to run.
Empty,
}

Expand Down
8 changes: 0 additions & 8 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ pub struct ParseError(Report);
pub enum FetchError {
#[error("Request failed.")]
RequestFailed,

#[error("Repository download failed with code {code}. {report}")]
RequestFailedWithCode { code: u16, report: Report },

#[error("Couldn't get the response body as bytes.")]
RequestBodyFailed,
}
Expand All @@ -57,7 +55,6 @@ pub enum FetchError {
pub enum RemoteError {
#[error("Failed to create a detached in-memory remote.\n\n{url}")]
CreateDetachedRemoteFailed { url: Report },

#[error("Failed to connect the given remote.\n\n{url}")]
ConnectionFailed { url: Report },
}
Expand All @@ -74,19 +71,14 @@ pub enum ReferenceError {
pub enum CheckoutError {
#[error("Failed to open the git repository.")]
OpenFailed(git2::Error),

#[error("Failed to parse revision string `{0}`.")]
RevparseFailed(String),

#[error("Failed to checkout revision (tree).")]
TreeCheckoutFailed,

#[error("Reference name is not a valid UTF-8 string.")]
InvalidRefName,

#[error("Failed to set HEAD to `{0}`.")]
SetHeadFailed(String),

#[error("Failed to detach HEAD to `{0}`.")]
DetachHeadFailed(String),
}
Expand Down

0 comments on commit 04be77c

Please sign in to comment.