Skip to content

Commit

Permalink
Merge pull request #3180 from tertsdiepraam/long_help_file
Browse files Browse the repository at this point in the history
Create `help_section` macro and use it for `numfmt`
  • Loading branch information
tertsdiepraam authored Aug 20, 2022
2 parents 5694de7 + 2130b3e commit 26b7099
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 64 deletions.
17 changes: 17 additions & 0 deletions src/uu/base32/base32.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# base32

## Usage
```
base32 [OPTION]... [FILE]
```

## About

encode/decode data and print to standard output
With no FILE, or when FILE is -, read standard input.

The data are encoded as described for the base32 alphabet in RFC
4648. When decoding, the input may contain newlines in addition
to the bytes of the formal base32 alphabet. Use --ignore-garbage
to attempt to recover from any other non-alphabet bytes in the
encoded stream.
16 changes: 3 additions & 13 deletions src/uu/base32/src/base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,12 @@
use std::io::{stdin, Read};

use clap::Command;
use uucore::{encoding::Format, error::UResult};
use uucore::{encoding::Format, error::UResult, help_section, help_usage};

pub mod base_common;

static ABOUT: &str = "\
encode/decode data and print to standard output
With no FILE, or when FILE is -, read standard input.
The data are encoded as described for the base32 alphabet in RFC
4648. When decoding, the input may contain newlines in addition
to the bytes of the formal base32 alphabet. Use --ignore-garbage
to attempt to recover from any other non-alphabet bytes in the
encoded stream.
";

const USAGE: &str = "{} [OPTION]... [FILE]";
const ABOUT: &str = help_section!("about", "base32.md");
const USAGE: &str = help_usage!("base32.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Expand Down
17 changes: 17 additions & 0 deletions src/uu/base64/base64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# base64

## Usage
```
base64 [OPTION]... [FILE]
```

## About

encode/decode data and print to standard output
With no FILE, or when FILE is -, read standard input.

The data are encoded as described for the base64 alphabet in RFC
3548. When decoding, the input may contain newlines in addition
to the bytes of the formal base64 alphabet. Use --ignore-garbage
to attempt to recover from any other non-alphabet bytes in the
encoded stream.
16 changes: 3 additions & 13 deletions src/uu/base64/src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@
use uu_base32::base_common;
pub use uu_base32::uu_app;

use uucore::{encoding::Format, error::UResult};
use uucore::{encoding::Format, error::UResult, help_section, help_usage};

use std::io::{stdin, Read};

static ABOUT: &str = "\
encode/decode data and print to standard output
With no FILE, or when FILE is -, read standard input.
The data are encoded as described for the base64 alphabet in RFC
3548. When decoding, the input may contain newlines in addition
to the bytes of the formal base64 alphabet. Use --ignore-garbage
to attempt to recover from any other non-alphabet bytes in the
encoded stream.
";

const USAGE: &str = "{0} [OPTION]... [FILE]";
const ABOUT: &str = help_section!("about", "base64.md");
const USAGE: &str = help_usage!("base64.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Expand Down
47 changes: 47 additions & 0 deletions src/uu/numfmt/numfmt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- spell-checker:ignore N'th M'th -->
# numfmt

## Usage
```
numfmt [OPTION]... [NUMBER]...
```

## About

Convert numbers from/to human-readable strings

## Long Help

UNIT options:
none no auto-scaling is done; suffixes will trigger an error

auto accept optional single/two letter suffix:

1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576,

si accept optional single letter suffix:

1K = 1000, 1M = 1000000, ...

iec accept optional single letter suffix:

1K = 1024, 1M = 1048576, ...

iec-i accept optional two-letter suffix:

1Ki = 1024, 1Mi = 1048576, ...

FIELDS supports cut(1) style field ranges:
N N'th field, counted from 1
N- from N'th field, to end of line
N-M from N'th to M'th field (inclusive)
-M from first to M'th field (inclusive)
- all fields
Multiple fields/ranges can be separated with commas

FORMAT must be suitable for printing one floating-point argument '%f'.
Optional quote (%'f) will enable --grouping (if supported by current locale).
Optional width value (%10f) will pad output. Optional zero (%010f) width
will zero pad the number. Optional negative values (%-10f) will left align.
Optional precision (%.1f) will override the input determined precision.

41 changes: 4 additions & 37 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.

// spell-checker:ignore N'th M'th

use crate::errors::*;
use crate::format::format_and_print;
use crate::options::*;
Expand All @@ -18,47 +16,16 @@ use uucore::display::Quotable;
use uucore::error::UResult;
use uucore::format_usage;
use uucore::ranges::Range;
use uucore::{help_section, help_usage};

pub mod errors;
pub mod format;
pub mod options;
mod units;

static ABOUT: &str = "Convert numbers from/to human-readable strings";
static LONG_HELP: &str = "UNIT options:
none no auto-scaling is done; suffixes will trigger an error
auto accept optional single/two letter suffix:
1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576,
si accept optional single letter suffix:
1K = 1000, 1M = 1000000, ...
iec accept optional single letter suffix:
1K = 1024, 1M = 1048576, ...
iec-i accept optional two-letter suffix:
1Ki = 1024, 1Mi = 1048576, ...
FIELDS supports cut(1) style field ranges:
N N'th field, counted from 1
N- from N'th field, to end of line
N-M from N'th to M'th field (inclusive)
-M from first to M'th field (inclusive)
- all fields
Multiple fields/ranges can be separated with commas
FORMAT must be suitable for printing one floating-point argument '%f'.
Optional quote (%'f) will enable --grouping (if supported by current locale).
Optional width value (%10f) will pad output. Optional zero (%010f) width
will zero pad the number. Optional negative values (%-10f) will left align.
Optional precision (%.1f) will override the input determined precision.
";
const USAGE: &str = "{} [OPTION]... [NUMBER]...";
const ABOUT: &str = help_section!("about", "numfmt.md");
const LONG_HELP: &str = help_section!("long help", "numfmt.md");
const USAGE: &str = help_usage!("numfmt.md");

fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: &NumfmtOptions) -> UResult<()> {
for l in args {
Expand Down
Loading

0 comments on commit 26b7099

Please sign in to comment.