Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basenc is a brand-new gnu core utility (added less than 3 years ago!), which enables some more encodings.
- Loading branch information
Showing
12 changed files
with
290 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ splitn | |
trunc | ||
|
||
# * uutils | ||
basenc | ||
chcon | ||
chgrp | ||
chmod | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "uu_basenc" | ||
version = "0.0.7" | ||
authors = ["uutils developers"] | ||
license = "MIT" | ||
description = "basenc ~ (uutils) decode/encode input" | ||
|
||
homepage = "https://github.com/uutils/coreutils" | ||
repository = "https://github.com/uutils/coreutils/tree/master/src/uu/basenc" | ||
keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"] | ||
categories = ["command-line-utilities"] | ||
edition = "2018" | ||
|
||
[lib] | ||
path = "src/basenc.rs" | ||
|
||
[dependencies] | ||
clap = { version = "2.33", features = ["wrap_help"] } | ||
uucore = { version=">=0.0.9", package="uucore", path="../../uucore", features = ["encoding"] } | ||
uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } | ||
uu_base32 = { version=">=0.0.6", package="uu_base32", path="../base32"} | ||
|
||
[[bin]] | ||
name = "basenc" | ||
path = "src/main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// This file is part of the uutils coreutils package. | ||
// | ||
// (c) Jordy Dickinson <jordy.dickinson@gmail.com> | ||
// (c) Jian Zeng <anonymousknight96@gmail.com> | ||
// | ||
// For the full copyright and license information, please view the LICENSE file | ||
// that was distributed with this source code. | ||
|
||
//spell-checker:ignore (args) lsbf msbf | ||
|
||
#[macro_use] | ||
extern crate uucore; | ||
|
||
use clap::{crate_version, App, Arg}; | ||
use uu_base32::base_common::{self, Config}; | ||
|
||
use uucore::{encoding::Format, InvalidEncodingHandling}; | ||
|
||
use std::io::{stdin, Read}; | ||
|
||
static ABOUT: &str = " | ||
With no FILE, or when FILE is -, read standard input. | ||
When decoding, the input may contain newlines in addition to the bytes of | ||
the formal alphabet. Use --ignore-garbage to attempt to recover | ||
from any other non-alphabet bytes in the encoded stream. | ||
"; | ||
|
||
static BASE_CMD_PARSE_ERROR: i32 = 1; | ||
|
||
const ENCODINGS: &[(&str, Format)] = &[ | ||
("base64", Format::Base64), | ||
("base64url", Format::Base64Url), | ||
("base32", Format::Base32), | ||
("base32hex", Format::Base32Hex), | ||
("base16", Format::Base16), | ||
("base2lsbf", Format::Base2Lsbf), | ||
("base2msbf", Format::Base2Msbf), | ||
("z85", Format::Z85), | ||
// common abbreviations. TODO: once we have clap 3.0 we can use `AppSettings::InferLongArgs` to get all abbreviations automatically | ||
("base2l", Format::Base2Lsbf), | ||
("base2m", Format::Base2Msbf), | ||
]; | ||
|
||
fn get_usage() -> String { | ||
format!("{0} [OPTION]... [FILE]", executable!()) | ||
} | ||
|
||
pub fn uu_app() -> App<'static, 'static> { | ||
let mut app = base_common::base_app(executable!(), crate_version!(), ABOUT); | ||
for encoding in ENCODINGS { | ||
app = app.arg(Arg::with_name(encoding.0).long(encoding.0)); | ||
} | ||
app | ||
} | ||
|
||
fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) { | ||
let usage = get_usage(); | ||
let matches = uu_app().usage(&usage[..]).get_matches_from( | ||
args.collect_str(InvalidEncodingHandling::ConvertLossy) | ||
.accept_any(), | ||
); | ||
let format = ENCODINGS | ||
.iter() | ||
.find(|encoding| matches.is_present(encoding.0)) | ||
.unwrap_or_else(|| { | ||
show_usage_error!("missing encoding type"); | ||
std::process::exit(1) | ||
}) | ||
.1; | ||
( | ||
Config::from("basenc", &matches).unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s)), | ||
format, | ||
) | ||
} | ||
|
||
pub fn uumain(args: impl uucore::Args) -> i32 { | ||
let name = executable!(); | ||
let (config, format) = parse_cmd_args(args); | ||
// Create a reference to stdin so we can return a locked stdin from | ||
// parse_base_cmd_args | ||
let stdin_raw = stdin(); | ||
let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw); | ||
|
||
base_common::handle_input( | ||
&mut input, | ||
format, | ||
config.wrap_cols, | ||
config.ignore_garbage, | ||
config.decode, | ||
name, | ||
); | ||
|
||
0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uucore_procs::main!(uu_basenc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.