Crates.io | naming_clt |
lib.rs | naming_clt |
version | 1.1.0 |
source | src |
created_at | 2021-11-03 12:36:54.650987 |
updated_at | 2021-12-28 06:57:06.630016 |
description | 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. |
homepage | https://github.com/boholder/naming |
repository | https://github.com/boholder/naming |
max_upload_size | |
id | 476136 |
size | 56,037 |
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.
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...)
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.
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.