#casing #refactoring #cli-tool #word #style #command-line #preserving

bin+lib altr

CLI tool to alter words seamlessly while preserving casing

11 releases (4 breaking)

new 0.5.0 May 9, 2024
0.4.0 May 9, 2024
0.3.5 May 5, 2024
0.3.4 Feb 1, 2024
0.1.0 Jan 23, 2024

#883 in Command line utilities

Download history 6/week @ 2024-01-24 17/week @ 2024-01-31 10/week @ 2024-02-14 25/week @ 2024-02-21 138/week @ 2024-05-01

138 downloads per month

MIT license

27KB
675 lines

Altr: Smart CLI Refactoring Tool

Overview

Altr is a robust command-line refactoring tool designed to effortlessly enhance your codebase while maintaining your preferred casing styles.

How to Use

Execute Altr with the following command:

altr <termToReplace> <replacementTerm> -f <path>

Example

Let's take a look at a practical scenario using a file named programmer.js, where we want to rename "programmer" to "rustProgrammer".

const programmer = new Programmer(Adam);

function getProgrammerName(programmer: Programmer) {
    return programmer.name;
}

// Updating the name for the PROGRAMMER
function setProgrammerName(name: string) {
    programmer.name = name; 
}

Executing the command:

altr programmer rustProgrammer -f programmer.js

Results in the following updated file:

const rustProgrammer = new RustProgrammer(Adam);

function getRustProgrammerName(rustProgrammer: RustProgrammer) {
    return rustProgrammer.name;
}

// Updating the name for the RUST_PROGRAMMER
function setRustProgrammerName(name: string) {
    rustProgrammer.name = name; 
}

Altr intelligently handles the replacement, considering the casing styles of both the original term and the specified replacement term. For instance, if we run:

altr programmer rust_programmer -f programmer.js

The tool adjusts the file accordingly:

const rust_programmer = new RustProgrammer(Adam);

function getRustProgrammerName(rust_programmer: RustProgrammer) {
    return rust_programmer.name;
}

// Updating the name for the RUST_PROGRAMMER
function setRustProgrammerName(name: string) {
    rust_programmer.name = name; 
}

Notice how Altr adapts to the casing requirements of the replacement term.

IO Support

Altr supports taking in input from stdin and passing it to stdout

$ echo "programmer" | altr programmer rust_programmer
$ rust_programmer

You can also specify the output location

altr programmer rust_programmer -f programmer.js -o rust-programmer.js

You can use "-" as path to indicate stdin or stdout as well

Installation

Altr is easily installed using cargo:

cargo install altr

Dependencies

~2.5MB
~51K SLoC