naming_clt

Crates.ionaming_clt
lib.rsnaming_clt
version1.1.0
sourcesrc
created_at2021-11-03 12:36:54.650987
updated_at2021-12-28 06:57:06.630016
descriptionExtract and convert the naming format(case|notation) of identifiers from files or stdin. Use this tool to prepare identifier name strings for further operations (matching,replacing...) on relative files.
homepagehttps://github.com/boholder/naming
repositoryhttps://github.com/boholder/naming
max_upload_size
id476136
size56,037
boholder (boholder)

documentation

https://github.com/boholder/naming

README

naming

CI Crates Version

naming is a command line tool that helps you extract and convert the naming format (case|notation) of identifiers from files or stdin. Use this tool to prepare identifier name strings for further operations (matching,replacing...) on relative files.

Quick links

What it can do?

You can convert identifiers to different naming cases, with multiple output formats.

$ echo "userId" | naming
userId USER_ID user_id user-id userId UserId

$ echo "userId" | naming --json
{"result":[{"origin":"userId","screaming_snake":"USER_ID","snake":"user_id",
"kebab":"user-id","camel":"userId","pascal":"UserId"}]}

$ echo "userId" | naming --regex
userId USER_ID|user_id|user-id|userId|UserId

You can extract identifiers from files or stdin(via pipe, have shown above).

$ cat a.txt
SCREAMING_SNAKE
snake_case
kebab-case
camelCase
PascalCase
$ naming a.txt
SCREAMING_SNAKE SCREAMING_SNAKE screaming_snake screaming-snake screamingSnake ScreamingSnake
snake_case SNAKE_CASE snake_case snake-case snakeCase SnakeCase
kebab-case KEBAB_CASE kebab_case kebab-case kebabCase KebabCase
camelCase CAMEL_CASE camel_case camel-case camelCase CamelCase
PascalCase PASCAL_CASE pascal_case pascal-case pascalCase PascalCase

The following example is more complex than entering commands manually, but it automates the process, which is why we made this tool in the first place. By combining this tool with others, you can write shell scripts about identifier format relative jobs.

# Search all positions of an identifier in project directory
$ echo "pageSize" | naming | xargs -n1 -I {} -- grep -r {} src_dir

# Change one identifier from camelCase to snake_case
$ echo "pageSize" | naming --output=s | \
    xargs -l -t -- bash -c 'sed -i "s/$0/$1/g" src_file'
bash -c 'sed -i "s/$0/$1/g" src_file' pageSize page_size
(^-- `xargs -t` output) (run sed command...)

Installation

We provide pre-compiled binaries for x86_64-pc-windows-gnu, x86_64-unknown-linux-musl and x86_64-apple-darwin platforms, you can download them at release page.

You can also build it (assuming you alreay have installed Rust dev toolchain) directly from source code ("nightly" version?), following the building progress.

Or just type:

$ cargo install naming_clt

to install a stable version.

Building

Just routine process will work:

$ git clone https://github.com/boholder/naming
$ cd naming
$ cargo build --release
$ ./target/release/naming --help
$ (print help information)

After cloning the source to your local machine, you can run all tests via:

$ cd naming
$ cargo test --all

There are two ignored tests , don't mind, these two tests made us to narrow down the capabilities of the tool, avoid duplicate implementing grep's functionality.

Contribution

  • Does the user guide and help information sound natural? Help us fix grammatical errors and polish the description.
  • When you found a bug or have suggestions, feel free to submit new issues.
  • What command line tools is this tool suitable for use in combination with? Have you found any useful ways to use this tool? Feel free to submit an issue or PR to share your findings.
Commit count: 62

cargo fmt