#env-var #variables #environment #delete #name #file #cross-platform

app envfetch

Lightweight cross-platform CLI tool for working with environment variables

2 stable releases

new 1.0.1 Dec 4, 2024
1.0.0 Nov 30, 2024

#162 in Command line utilities

Download history 208/week @ 2024-11-29

208 downloads per month

MIT license

15KB
148 lines

envfetch

Lightweight cross-platform CLI tool for working with environment variables
Build status Test status GitHub commit activity crates.io downloads crates.io version

Features

  • Print all environment variables
  • Get value of variable by name
    • Show similar variables if variable not found
  • Set variable
  • Delete variable
  • Load variables from dotenv-style file
  • Globally set variables
  • Globally delete variables
  • Globally load variables from dotenv-style file
  • Set and delete multiple variables at once

Get started

Installing

You can install envfetch from Cargo (needs Rust installed):

$ cargo install envfetch

Also, you can install it from source (needs Rust installed):

$ cargo install --git https://github.com/ankddev/envfetch envfetch

Or, get binary from GitHub Actions (needs GutHub account) or releases

Using

To run envfetch, run envfetch <COMMAND> <ARGS> in your terminal. You can run envfetch help to see help message or envfetch --version to see program's version.

Command list

Set

Set environment variable and run process.

[!NOTE] Now variable sets only for one run

Usage: envfetch set <KEY> <VALUE> <PROCESS>, where:

  • KEY - name of environment variable
  • VALUE - value of environment variable
  • PROCESS - name of process which you want to run

Options:

  • --help/-h - show help message

For example:

$ envfetch set MY_VAR "Hello" "npm run"

It will set environment variable with name MY_VAR value "Hello" and start npm run

Print

Print all environment variables

Usage: envfetch print

Options:

  • --help/-h - show help message

For example:

$ envfetch print
SHELL = "powershell"
windir = "C:\\Windows"
SystemDrive = "C:"
SystemRoot = "C:\\Windows"
...

It will print all environment variables in format VAR = "VALUE".

Get

Get value of environment variable

Usage: envfetch get <KEY>, where:

  • KEY - name of environment variable

Options:

  • --help/-h - show help message
  • --no-similar-names/-s - disable showing similar variables if variable not

For example:

$ envfetch get MY_VAR
"Hello"

It will print value of specified variable.

Delete

Delete variable and start process.

[!NOTE] Now variable deletes only for one run

Usage: envfetch delete <KEY> <PROCESS>, where:

  • KEY - name of environment variable
  • PROCESS - name of command to run

Options:

  • --help/-h - show help message

For example:

$ envfetch delete MY_VAR "npm run"

It will delete variable MY_VAR and run npm run command.

Load

Load environment variables from dotenv-style file and run process.

[!NOTE] Now variables set only for one run

Usage: envfetch load <PROCESS>, where:

  • PROCESS - name of process which you want to run

Options:

  • --help/-h - show help message
  • --file <FILE>/-f <FILE> - relative or absolute path to file to read variables from. Note that it must in .env format. By default, program loads variables from .env file in current directory.

For example:

$ envfetch load "npm run"
$ envfetch load "npm run" --file ".env.debug"

It will load variables from .env or .env.debug and start npm run

Building from source

  • Install Rust. If it already installed, update with
$ rustup update
  • Fork this project using button Fork on the top of this page
  • Clone your fork (replace <YOUR_USERNAME> with your username on GitHub):
$ git clone https://github.com/<YOUR_USERNAME>/envfetch.git
  • Go to directory, where you cloned envfetch:
$ cd envfetch
  • Run program using Cargo (replace <COMMAND> and <ARGS> to your command and args):
$ cargo run -- <COMMAND> <ARGS>

Contributing

$ cargo fmt
$ cargo clippy --fix
  • Run tests with
$ cargo test
  • Push changes
  • Open pull request

Dependencies

~3–14MB
~119K SLoC