Skip to content

Commit

Permalink
chore: make cli module public
Browse files Browse the repository at this point in the history
We need the cli in both the binary and the library, which are separate
crates. In order to keep it private, we were compiling it twice,
incurring costs to compilation time and binary size. This is not worth
it.
  • Loading branch information
sandydoo committed Sep 27, 2024
1 parent b5daa5c commit 0c58894
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 33 deletions.
16 changes: 8 additions & 8 deletions devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use std::path::PathBuf;
dont_delimit_trailing_values = true,
about = format!("https://devenv.sh {}: Fast, Declarative, Reproducible, and Composable Developer Environments", crate_version!())
)]
pub(crate) struct Cli {
pub struct Cli {
#[command(subcommand)]
pub(crate) command: Commands,
pub command: Commands,

#[command(flatten)]
pub(crate) global_options: GlobalOptions,
pub global_options: GlobalOptions,
}

impl Cli {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl GlobalOptions {
}

#[derive(Subcommand, Clone)]
pub(crate) enum Commands {
pub enum Commands {
#[command(about = "Scaffold devenv.yaml, devenv.nix, .gitignore and .envrc.")]
Init {
target: Option<PathBuf>,
Expand Down Expand Up @@ -270,7 +270,7 @@ pub(crate) enum Commands {

#[derive(Subcommand, Clone)]
#[clap(about = "Start or stop processes. https://devenv.sh/processes/")]
pub(crate) enum ProcessesCommand {
pub enum ProcessesCommand {
#[command(alias = "start", about = "Start processes in the foreground.")]
Up {
process: Option<String>,
Expand All @@ -286,7 +286,7 @@ pub(crate) enum ProcessesCommand {

#[derive(Subcommand, Clone)]
#[clap(about = "Run tasks. https://devenv.sh/tasks/")]
pub(crate) enum TasksCommand {
pub enum TasksCommand {
#[command(about = "Run tasks.")]
Run { tasks: Vec<String> },
}
Expand All @@ -296,7 +296,7 @@ pub(crate) enum TasksCommand {
about = "Build, copy, or run a container. https://devenv.sh/containers/",
arg_required_else_help(true)
)]
pub(crate) enum ContainerCommand {
pub enum ContainerCommand {
#[command(about = "Build a container.")]
Build { name: String },

Expand All @@ -309,7 +309,7 @@ pub(crate) enum ContainerCommand {

#[derive(Subcommand, Clone)]
#[clap(about = "Add an input to devenv.yaml. https://devenv.sh/inputs/")]
pub(crate) enum InputsCommand {
pub enum InputsCommand {
#[command(about = "Add an input to devenv.yaml.")]
Add {
#[arg(help = "The name of the input.")]
Expand Down
20 changes: 11 additions & 9 deletions devenv/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,30 @@ pub struct DevenvOptions {
}

pub struct Devenv {
pub(crate) config: config::Config,
pub(crate) global_options: cli::GlobalOptions,
pub config: config::Config,
pub global_options: cli::GlobalOptions,

pub(crate) logger: log::Logger,
pub(crate) log_progress: log::LogProgressCreator,
logger: log::Logger,
log_progress: log::LogProgressCreator,

nix: cnix::Nix<'static>,

// All kinds of paths
xdg_dirs: xdg::BaseDirectories,
pub(crate) devenv_root: PathBuf,
devenv_root: PathBuf,
devenv_dotfile: PathBuf,
devenv_dot_gc: PathBuf,
devenv_home_gc: PathBuf,
devenv_tmp: String,
devenv_runtime: PathBuf,

pub(crate) assembled: bool,
pub(crate) dirs_created: bool,
pub(crate) has_processes: Option<bool>,
assembled: bool,
dirs_created: bool,
has_processes: Option<bool>,

pub(crate) container_name: Option<String>,
// TODO: make private.
// Pass as an arg or have a setter.
pub container_name: Option<String>,
}

impl Devenv {
Expand Down
4 changes: 2 additions & 2 deletions devenv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod cli;
pub mod cnix;
pub mod cli;
pub(crate) mod cnix;
pub mod config;
mod devenv;
pub mod log;
Expand Down
15 changes: 5 additions & 10 deletions devenv/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
mod cli;
mod cnix;
mod config;
mod devenv;
mod log;
mod tasks;

use clap::{crate_version, Parser};
use cli::{Cli, Commands, ContainerCommand, InputsCommand, ProcessesCommand, TasksCommand};
use devenv::Devenv;
use clap::crate_version;
use devenv::{
cli::{Cli, Commands, ContainerCommand, InputsCommand, ProcessesCommand, TasksCommand},
config, log, Devenv,
};
use miette::Result;

#[tokio::main]
Expand Down
1 change: 0 additions & 1 deletion xtask/src/cli.rs

This file was deleted.

1 change: 0 additions & 1 deletion xtask/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub(crate) mod cli;
pub mod manpage;
pub mod shell_completion;
2 changes: 1 addition & 1 deletion xtask/src/manpage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::cli::Cli;
use clap::CommandFactory;
use devenv::cli::Cli;
use miette::{IntoDiagnostic, Result};
use std::fs;
use std::path::{Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/shell_completion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli::Cli;
use clap::CommandFactory;
use devenv::cli::Cli;
use miette::{IntoDiagnostic, Result};
use std::fs;
use std::path::{Path, PathBuf};
Expand Down

0 comments on commit 0c58894

Please sign in to comment.