Skip to content
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/mono/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ clap.workspace = true
cliclack.workspace = true
console.workspace = true
semver.workspace = true
serde.workspace = true
tempfile.workspace = true
toml.workspace = true
thiserror.workspace = true
12 changes: 9 additions & 3 deletions crates/mono/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ use mono_repository::Repository;
use crate::Context;

mod command;
mod config;
mod error;

pub use command::{Command, Commands};
pub use config::Config;
pub use error::Result;

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -78,11 +80,15 @@ pub struct Cli {
// ----------------------------------------------------------------------------

impl Cli {
pub fn execute<T>(self, repository: Repository, workspace: Workspace<T>)
where
pub fn execute<T>(
self, repository: Repository, workspace: Workspace<T>, config: Config,
) where
T: Manifest,
{
match self.command.execute(Context { repository, workspace }) {
match self
.command
.execute(Context { repository, workspace, config })
{
Ok(()) => process::exit(0),
Err(err) => {
eprintln!("Error: {err}");
Expand Down
5 changes: 4 additions & 1 deletion crates/mono/src/cli/command/version/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ where
// Resolve versions and create changeset, then determine all commits
// that are either part of the given version or yet unreleased
let versions = context.repository.versions()?;
let mut changeset = Changeset::new(&context.workspace)?;
let mut changeset = Changeset::with_config(
&context.workspace,
&context.config.changeset,
)?;
for res in versions.commits(self.version.as_ref())? {
changeset.add(res?)?;
}
Expand Down
42 changes: 42 additions & 0 deletions crates/mono/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2025 Zensical and contributors

// SPDX-License-Identifier: MIT
// Third-party contributions licensed under DCO

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

// ----------------------------------------------------------------------------

//! Configuration.

use serde::Deserialize;

use mono_changeset as changeset;

// ----------------------------------------------------------------------------
// Structs
// ----------------------------------------------------------------------------

/// Configuration.
#[derive(Debug, Default, Deserialize)]
pub struct Config {
/// Changeset.
#[serde(default)]
pub changeset: changeset::Config,
}
3 changes: 3 additions & 0 deletions crates/mono/src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum Error {
/// I/O error.
#[error(transparent)]
Io(#[from] io::Error),
/// TOML error.
#[error(transparent)]
Toml(#[from] toml::de::Error),
/// Version error.
#[error(transparent)]
Version(#[from] semver::Error),
Expand Down
20 changes: 17 additions & 3 deletions crates/mono/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
//! Command line interface.

use clap::Parser;
use std::fs;

use mono_project::{Cargo, Manifest, Node, Workspace};
use mono_repository::Repository;

mod cli;

use cli::{Cli, Result};
use cli::{Cli, Config, Result};

// ----------------------------------------------------------------------------
// Structs
Expand All @@ -48,6 +49,8 @@ where
repository: Repository,
/// Workspace.
workspace: Workspace<T>,
/// Configuration.
config: Config,
}

// ----------------------------------------------------------------------------
Expand All @@ -59,10 +62,21 @@ fn main() -> Result {
let cli = Cli::parse();
let repository = Repository::open(&cli.directory)?;
let path = repository.path();

// Try to load configuraiton, if any
let config_path = path.join(".mono.toml");
let config = if config_path.exists() {
let contents = fs::read_to_string(&config_path)?;
toml::from_str(&contents)?
} else {
Config::default()
};

// Initialize cargo or node workspace
if let Ok(workspace) = Workspace::<Cargo>::resolve(path) {
cli.execute(repository, workspace);
cli.execute(repository, workspace, config);
} else if let Ok(workspace) = Workspace::<Node>::resolve(path) {
cli.execute(repository, workspace);
cli.execute(repository, workspace, config);
}

// No errors occurred
Expand Down