Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cp: compile without clap (for nushell) #5358

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
733066c
let cp can without clap dep when no-default-features flag is specific
tommady Oct 5, 2023
1955616
let uucore clap can be optional
tommady Oct 5, 2023
b29b31f
let cp can optional out uucore clap
tommady Oct 5, 2023
2f68fd4
let clap dep could be optional in the uucore
tommady Oct 5, 2023
fe47bf0
fix date is using the uucore clap
tommady Oct 5, 2023
4cb66c4
Update src/uucore/src/lib/mods/error.rs
tommady Oct 5, 2023
d867b1b
use dep:clap instead of just a clap to mark this feature is depends o…
tommady Oct 6, 2023
4362184
fix-5203 but cargo tree --no-default uucore still has clap dep
tommady Oct 6, 2023
9f0f0a9
Merge branch 'fix-5203' of github.com:tommady/coreutils into fix-5203
tommady Oct 6, 2023
af8690d
fixing clippy and check errors
tommady Oct 7, 2023
968e901
let cp can without clap dep when no-default-features flag is specific
tommady Oct 5, 2023
fea371a
let uucore clap can be optional
tommady Oct 5, 2023
27e2dc4
let cp can optional out uucore clap
tommady Oct 5, 2023
ee93c10
let clap dep could be optional in the uucore
tommady Oct 5, 2023
33db724
fix date is using the uucore clap
tommady Oct 5, 2023
e28c71d
Update src/uucore/src/lib/mods/error.rs
tommady Oct 5, 2023
243fa6a
use dep:clap instead of just a clap to mark this feature is depends o…
tommady Oct 6, 2023
51cf10f
fix-5203 but cargo tree --no-default uucore still has clap dep
tommady Oct 6, 2023
c08de95
fixing clippy and check errors
tommady Oct 7, 2023
20735c9
cp: fix formatting of Cargo.toml
cakebaker Oct 15, 2023
10f5d98
remove temp unused allow(dead_code)
tommady Oct 16, 2023
e38bcf3
Merge branch 'fix-5203' of github.com:tommady/coreutils into fix-5203
tommady Oct 16, 2023
fea1a2e
remove temp unused allow(dead_code)
tommady Oct 16, 2023
7c2adb5
fix the style toml check
tommady Oct 16, 2023
a54dd0e
Merge branch 'main' into fix-5203
tommady Oct 16, 2023
7f5d90a
cp: fix formatting of Cargo.toml
cakebaker Oct 17, 2023
8ca000e
Merge branch 'main' into fix-5203
tommady Dec 26, 2023
8efa790
fix cargo fmt
tommady Dec 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/uu/cp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ edition = "2021"
path = "src/cp.rs"

[dependencies]
clap = { workspace = true }
clap = { workspace = true, optional = true }
filetime = { workspace = true }
libc = { workspace = true }
quick-error = { workspace = true }
Expand All @@ -44,5 +44,7 @@ name = "cp"
path = "src/main.rs"

[features]
default = ["cli-parser"]
feat_selinux = ["selinux"]
feat_acl = ["exacl"]
cli-parser = ["clap", "uucore/cli-parser"]
tommady marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/uu/date/Cargo.toml
tommady marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/date.rs"
[dependencies]
chrono = { workspace = true }
clap = { workspace = true }
uucore = { workspace = true }
uucore = { workspace = true, features = ["cli-parser"] }
parse_datetime = { workspace = true }

[target.'cfg(unix)'.dependencies]
Expand Down
3 changes: 2 additions & 1 deletion src/uucore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ edition = "2021"
path = "src/lib/lib.rs"

[dependencies]
clap = { workspace = true }
clap = { workspace = true, optional = true }
uucore_procs = { workspace = true }
dns-lookup = { version = "2.0.3", optional = true }
dunce = { version = "1.0.4", optional = true }
Expand Down Expand Up @@ -103,3 +103,4 @@ utf8 = []
utmpx = ["time", "time/macros", "libc", "dns-lookup"]
version-cmp = []
wide = []
cli-parser = ["clap"]
1 change: 1 addition & 0 deletions src/uucore/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use crate::mods::panic;
pub use crate::parser::parse_glob;
pub use crate::parser::parse_size;
pub use crate::parser::parse_time;
#[cfg(feature = "cli-parser")]
pub use crate::parser::shortcut_value_parser;

// * feature-gated modules
Expand Down
10 changes: 10 additions & 0 deletions src/uucore/src/lib/mods/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

// spell-checker:ignore uioerror rustdoc

// In case we want to build without clap support
// Example: nushell
#[cfg(feature = "cli-parser")]
tommady marked this conversation as resolved.
Show resolved Hide resolved
use clap;
use std::{
error::Error,
Expand Down Expand Up @@ -688,6 +691,7 @@ impl From<i32> for Box<dyn UError> {
/// let result: Result<_, Box<dyn UError>> = command.try_get_matches().map_err(Into::into);
/// ```
#[derive(Debug)]
#[cfg(feature = "cli-parser")]
pub struct ClapErrorWrapper {
code: i32,
error: clap::Error,
Expand All @@ -698,18 +702,21 @@ pub trait UClapError<T> {
fn with_exit_code(self, code: i32) -> T;
}

#[cfg(feature = "cli-parser")]
impl From<clap::Error> for Box<dyn UError> {
fn from(e: clap::Error) -> Self {
Box::new(ClapErrorWrapper { code: 1, error: e })
}
}

#[cfg(feature = "cli-parser")]
impl UClapError<ClapErrorWrapper> for clap::Error {
fn with_exit_code(self, code: i32) -> ClapErrorWrapper {
ClapErrorWrapper { code, error: self }
}
}

#[cfg(feature = "cli-parser")]
impl UClapError<Result<clap::ArgMatches, ClapErrorWrapper>>
for Result<clap::ArgMatches, clap::Error>
{
Expand All @@ -718,6 +725,7 @@ impl UClapError<Result<clap::ArgMatches, ClapErrorWrapper>>
}
}

#[cfg(feature = "cli-parser")]
impl UError for ClapErrorWrapper {
fn code(&self) -> i32 {
// If the error is a DisplayHelp or DisplayVersion variant,
Expand All @@ -733,9 +741,11 @@ impl UError for ClapErrorWrapper {
}
}

#[cfg(feature = "cli-parser")]
impl Error for ClapErrorWrapper {}

// This is abuse of the Display trait
#[cfg(feature = "cli-parser")]
impl Display for ClapErrorWrapper {
fn fmt(&self, _f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
self.error.print().unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/uucore/src/lib/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
pub mod parse_glob;
pub mod parse_size;
pub mod parse_time;
#[cfg(feature = "cli-parser")]
pub mod shortcut_value_parser;