Skip to content
Open
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
72 changes: 20 additions & 52 deletions src/changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,46 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

//! Changed-file command execution.
//! Changed-file command helpers.

use std::{
ffi::OsStr,
path::{Path, PathBuf},
};
use std::path::Path;

use snafu::{ResultExt, Whatever};

use crate::{cli::ChangedFormat, config::RepositoryUse, git, layout::REPO_DIR};

pub(crate) fn is_proposal_path(mut p: PathBuf) -> bool {
// Only lint `content/00001.md` and `content/00001/index.md` files.

// content/00000.md | content/00000/index.md
// ^^^^^^^^ | ^^^^^^^^
match p.file_name() {
Some(n) if n == "index.md" => {
p.pop();
}
Some(_) if p.extension().map(|x| x == "md").unwrap_or(false) => {
p.set_extension("");
}
None | Some(_) => return false,
}

// content/00000
// ^^^^^
match p.file_name().and_then(OsStr::to_str) {
None => return false,
Some(f) if f.parse::<u64>().is_err() => return false,
Some(_) => {
p.pop();
}
}

// content
// ^^^^^^^
match p.file_name() {
Some(f) if f == "content" => {
p.pop();
}
_ => return false,
}

p == OsStr::new("")
}
use crate::{
cli::ChangedFormat, execution::ResolvedExecution, git, layout::REPO_DIR,
proposal::is_proposal_path,
};

pub(crate) fn run(
root_path: &Path,
resolved: &ResolvedExecution,
build_path: &Path,
repo_use: RepositoryUse,
all: bool,
format: &ChangedFormat,
) -> Result<(), Whatever> {
let repo_path = build_path.join(REPO_DIR);

let both = git::Fresh::new(root_path, &repo_path, repo_use)
.whatever_context("initializing build repo")?
.clone_src()
.whatever_context("cloning source repo")?
.fetch_upstream()
.whatever_context("fetching upstream repo")?;
let both = git::Fresh::new(
&resolved.root_path,
&repo_path,
resolved.repository_use.clone(),
resolved.source_materialization,
)
.whatever_context("initializing build repo")?
.clone_src()
.whatever_context("cloning source repo")?
.fetch_upstream()
.whatever_context("fetching upstream repo")?;

let changed_files: Vec<_> = both
.changed_files()
.whatever_context("unable to list changed files")?
.into_iter()
.filter(|p| all || is_proposal_path(p.into()))
.filter(|p| all || is_proposal_path(p))
.map(|p| repo_path.join(p))
.collect();

format.print(&changed_files, &repo_path);

Ok(())
}
100 changes: 95 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use std::path::{Path, PathBuf};

use clap::{Parser, Subcommand};
use url::Url;

use crate::{lint, print};
use crate::print;

/// Build script for Ethereum EIPs and ERCs.
#[derive(Parser, Debug)]
Expand All @@ -20,11 +21,33 @@ pub(crate) struct Args {
#[clap(short = 'C')]
pub(crate) root: Option<PathBuf>,

/// Use the configured remote sibling content repositories
#[clap(long)]
pub(crate) remote_siblings: bool,

/// Write build artifacts under BUILD_ROOT instead of the default location
#[clap(long)]
pub(crate) build_root: Option<PathBuf>,

#[clap(subcommand)]
pub(crate) operation: Operation,
}

#[derive(Debug, Subcommand)]
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
pub(crate) struct BaseUrlCliArgs {
/// Override the rendered-site base URL for this command
#[arg(long, value_parser = clap::value_parser!(Url))]
pub(crate) base_url: Option<Url>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
pub(crate) struct CleanCliArgs {
/// Ignore tracked working-tree changes in the active repo
#[arg(long)]
pub(crate) clean: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub(crate) enum Operation {
/// Print various useful things, like available lints
Print {
Expand All @@ -35,13 +58,19 @@ pub(crate) enum Operation {
/// Build the project and output HTML
Build {
#[command(flatten)]
eipw: lint::CmdArgs,
base_url: BaseUrlCliArgs,

#[command(flatten)]
clean: CleanCliArgs,
},

/// Build the project and launch a web server to preview it
Serve {
#[command(flatten)]
eipw: lint::CmdArgs,
base_url: BaseUrlCliArgs,

#[command(flatten)]
clean: CleanCliArgs,
},

/// Remove temporary and output files
Expand All @@ -50,7 +79,7 @@ pub(crate) enum Operation {
/// Analyze the repository and report errors, but don't build HTML files
Check {
#[command(flatten)]
eipw: lint::CmdArgs,
clean: CleanCliArgs,
},

/// List files changed since the last commit common to both the local and upstream repositories
Expand All @@ -61,6 +90,67 @@ pub(crate) enum Operation {
#[clap(long, value_enum, default_value_t)]
format: ChangedFormat,
},

/// Create workspace config, docs, build root, and missing local repos
Init {
/// Workspace root directory
path: PathBuf,

/// Also clone template for proposal-family scaffold work
#[arg(long)]
template: bool,
},

/// Check workspace layout, local repos, and required tools
Doctor,
}

#[derive(Debug, Clone)]
pub(crate) enum RuntimeOperation {
Build,
Serve,
Clean,
Check,
Changed { all: bool, format: ChangedFormat },
}

impl Operation {
pub(crate) fn base_url_cli_args(&self) -> BaseUrlCliArgs {
match self {
Self::Build { base_url, .. } | Self::Serve { base_url, .. } => base_url.clone(),
_ => BaseUrlCliArgs::default(),
}
}

pub(crate) fn clean_cli_args(&self) -> CleanCliArgs {
match self {
Self::Build { clean, .. } | Self::Serve { clean, .. } | Self::Check { clean } => clean.clone(),
_ => CleanCliArgs::default(),
}
}

pub(crate) fn is_plain_site_command(&self) -> bool {
matches!(self, Self::Build { .. } | Self::Serve { .. } | Self::Check { .. })
}

pub(crate) fn runtime_operation(&self) -> Option<RuntimeOperation> {
match self {
Self::Print { .. } | Self::Init { .. } | Self::Doctor => None,
Self::Build { .. } => Some(RuntimeOperation::Build),
Self::Serve { .. } => Some(RuntimeOperation::Serve),
Self::Clean => Some(RuntimeOperation::Clean),
Self::Check { .. } => Some(RuntimeOperation::Check),
Self::Changed { all, format } => Some(RuntimeOperation::Changed { all: *all, format: format.clone() }),
}
}

pub(crate) fn is_workspace_lifecycle_command(&self) -> bool {
matches!(self, Self::Init { .. } | Self::Doctor)
}

pub(crate) fn is_print_command(&self) -> bool {
matches!(self, Self::Print { .. })
}
}

#[derive(Debug, clap::ValueEnum, Clone, Default)]
Expand Down
Loading
Loading