mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
move numfmt help to a separate file
This commit is contained in:
parent
9fad6fde35
commit
c4ba21f720
3 changed files with 85 additions and 38 deletions
42
src/uu/numfmt/help.md
Normal file
42
src/uu/numfmt/help.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
<!-- spell-checker:ignore N'th M'th -->
|
||||
# numfmt
|
||||
|
||||
## 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.
|
||||
|
|
@ -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::*;
|
||||
|
@ -17,47 +15,15 @@ use units::{IEC_BASES, SI_BASES};
|
|||
use uucore::display::Quotable;
|
||||
use uucore::error::UResult;
|
||||
use uucore::ranges::Range;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::{format_usage, help_section, InvalidEncodingHandling};
|
||||
|
||||
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 ABOUT: &str = help_section!("about");
|
||||
const LONG_HELP: &str = help_section!("long help");
|
||||
const USAGE: &str = "{} [OPTION]... [NUMBER]...";
|
||||
|
||||
fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: &NumfmtOptions) -> UResult<()> {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Copyright (C) ~ Roy Ivy III <rivy.dev@gmail.com>; MIT license
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
use std::{fs::File, io::Read, path::PathBuf};
|
||||
|
||||
use proc_macro::{Literal, TokenStream, TokenTree};
|
||||
use quote::quote;
|
||||
|
||||
//## rust proc-macro background info
|
||||
|
@ -34,3 +36,40 @@ pub fn main(_args: TokenStream, stream: TokenStream) -> TokenStream {
|
|||
|
||||
TokenStream::from(new)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn help_section(input: TokenStream) -> TokenStream {
|
||||
let input: Vec<TokenTree> = input.into_iter().collect();
|
||||
let value = match &input.get(0) {
|
||||
Some(TokenTree::Literal(literal)) => literal.to_string(),
|
||||
_ => panic!("Input to help_section should be a string literal!"),
|
||||
};
|
||||
let input_str: String = value.parse().unwrap();
|
||||
let input_str = input_str.to_lowercase().trim_matches('"').to_string();
|
||||
|
||||
let mut content = String::new();
|
||||
let mut path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
|
||||
path.push("help.md");
|
||||
|
||||
File::open(path)
|
||||
.unwrap()
|
||||
.read_to_string(&mut content)
|
||||
.unwrap();
|
||||
|
||||
let text = content
|
||||
.lines()
|
||||
.skip_while(|&l| {
|
||||
l.strip_prefix("##")
|
||||
.map_or(true, |l| l.trim().to_lowercase() != input_str)
|
||||
})
|
||||
.skip(1)
|
||||
.take_while(|l| !l.starts_with("##"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
let str = TokenTree::Literal(Literal::string(&text));
|
||||
str.into()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue