Skip to content

Commit

Permalink
complete remake (#1)
Browse files Browse the repository at this point in the history
* Initial commit for new empty branch

* feat: implemented chore functionality

* chore: add readme
  • Loading branch information
SameerJadav authored Jul 24, 2024
1 parent 0267359 commit cb262aa
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 413 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions LICENSE

This file was deleted.

104 changes: 38 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,83 @@
# Keyper

Keyper is a CLI tool for effortlessly managing your environment variables. Save environment variables locally and retrieve them with just one command. Built using only the standard libraries of Go. Keyper is simple, useful, and blazingly fast.

https://github.com/SameerJadav/keyper/assets/109742866/98ca1bb9-9773-436c-960a-5561fb6f0c75
Keyper is a CLI tool for effortlessly managing your environment variables.
Save environment variables locally and retrieve them with just one command.
Built using only the standard libraries of Go. Keyper is simple, useful, and blazingly fast.

# Table of Contents

- [Installation](#installation)
- [Usage Example](#usage-example)
- [Save Environment Variables](#save-environment-variables)
- [Retrieve Environment Variables](#retrieve-environment-variables)
- [Remove Environment Variables](#remove-environment-variables)
- [Purge Project and its Variables](#purge-project-and-its-variables)
- [Pro-Tip](#pro-tip)
- [Usage](#usage)
- [Save environment variables](#save-environment-variables)
- [Retrieve environment variables](#retrieve-environment-variables)
- [Remove environment variables](#remove-environment-variables)
- [Purge project or environment](#purge-project-or-environment)
- [Contributing](#contributing)
- [License](#license)

## Installation

To install Keyper, ensure you have Go installed on your machine. If you haven't installed Go yet, you can follow the [official Go installation instructions](https://go.dev/doc/install).
To install Keyper, ensure you have Go installed on your machine.
If you haven't installed Go yet, you can follow the [official Go installation instructions](https://go.dev/doc/install).

```
go install github.com/SameerJadav/keyper@latest
```

This will install a Go binary that automatically binds to your `$GOPATH`.

## Usage Example
## Usage

Keyper is designed for simplicity. It's a [grug brain tool](https://grugbrain.dev/#grug-on-tools).

### Save Environment Variables

**Command:**
### Save environment variables

```
keyper set <project> <key=value> ...
keyper set todo-list -e prod -f .env
```

**Example:**

```
keyper set my-project DATABASE_URL=postgresql://localhost/mydb DATABASE_AUTH_TOKEN=42069
```

Saves the specified key-value pairs as environment variables for the given project, overwriting existing variables with the same keys.

### Retrieve Environment Variables
This command sets environment variables for the "todo-list" project.
It uses the production environment (-e prod) and loads variables from .env file (-f .env).
You can also add `key=value` pairs directly in the command instead of using a file.
Run `keyper set --help` for more information.

**Command:**
### Retrieve environment variables

```
keyper get <project>
keyper get todo-list -e dev -o .env
```

**Example:**
This command retrieves environment variables for the "todo-list" project.
It fetches variables from the development environment (-e dev) and saves them to a file named .env (-o .env).
If -e is not specified, it retrieves variables for all environments.
If -o is not specified, variables are printed to the console.
Run `keyper get --help` for more information.

```
keyper get my-project
```

Displays the saved environment variables for the specified project.
### Remove environment variables

```
DATABASE_URL=postgresql://localhost/mydb
DATABASE_AUTH_TOKEN=42069
keyper remove todo-list -force -e prod API_KEY SECRET_TOKEN
```

### Remove Environment Variables
This command removes specified environment variables (API_KEY and SECRET_TOKEN) from the "todo-list" project in the production environment (-e prod).
The -force flag skips the confirmation prompt.
If -e is omitted, it removes the variables from all environments.
Run `keyper remove --help` for more information.

**Command:**
**Note: Use with caution as this action cannot be undone.**

```
keyper remove <project> <key> ...
```

**Example:**
### Purge project or environment

```
keyper remove my-project DATABASE_URL
keyper purge todo-list -force -e prod
```

Permanently removes the specified environment variables from the given project.

### Purge Project and its Variables
This command purges the "todo-list" project's production environment (-e prod).
The -force flag skips the confirmation prompt.
If -e is omitted, it purges the entire project and all its environments.
Run `keyper purge --help` for more information.

**Command:**

```
keyper purge <project> ...
```

**Example:**

```
keyper purge my-project
```

Permanently removes the entire project and all its associated environment variables. Use this command with caution.

### Pro-Tip

You can easily export environment variables to a `.env` file by just redirecting the result of the `keyper get` command to an `.env` file.

```
keyper get my-project > .env
```
**Note: Use with caution as this action cannot be undone.**

## Contributing

Expand Down
86 changes: 0 additions & 86 deletions cmd/keyper/keyper.go

This file was deleted.

73 changes: 73 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cmd

import (
"errors"
"flag"
"fmt"

"github.com/SameerJadav/keyper/internal/core"
)

func Execute() error {
var showHelp bool
flag.BoolVar(&showHelp, "help", false, "show help")
flag.BoolVar(&showHelp, "h", false, "show help (shorthand)")

flag.Parse()

usage := `Keyper is a CLI tool for effortlessly managing all your environment variables.
Save environment variables locally and retrieve them with just one command.
Keyper is simple, useful, and blazingly fast.
Usage:
keyper [flags] [command]
Commands:
set Set environment variables for a project
get Retrieve environment variables for a project
remove Remove specific environment variables from a project
purge Remove all environment variables for a project or environment
Flags:
-h, --help Show help information for Keyper or its subcommands
Examples:
keyper --help
keyper set myapp -e prod -f prod.env
keyper get myapp -e prod -o .env
keyper remove myapp --force -e prod API_KEY SECRET_TOKEN
keyper purge myapp --force
Use "keyper [command] --help" for more information about a command.
Learn more about the Keyper at https://github.com/SameerJadav/keyper`

args := flag.Args()

if len(args) == 0 || showHelp {
fmt.Println(usage)
return nil
}

switch args[0] {
case "set":
if err := core.Set(); err != nil {
return err
}
case "get":
if err := core.Get(); err != nil {
return err
}
case "purge":
if err := core.Purge(); err != nil {
return err
}
case "remove":
if err := core.Remove(); err != nil {
return err
}
default:
return errors.New("unknown command. run \"keyper --help\" for usage")
}

return nil
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/SameerJadav/keyper

go 1.22.0
go 1.22.5

require github.com/SameerJadav/envparse v1.0.0
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/SameerJadav/envparse v0.2.0 h1:2qgtdopNsA5iq9wB7oPEFJPWwrarrTmgwAWgw8BvJ50=
github.com/SameerJadav/envparse v0.2.0/go.mod h1:gTaqzFU/gbU/aIL4vhXs2FZtmzTcprJHfqhoijkC6lg=
github.com/SameerJadav/envparse v1.0.0 h1:BV1nzPdLh9Oe4duUauDszeNnwCtUTHYf0TJur4URrSM=
github.com/SameerJadav/envparse v1.0.0/go.mod h1:gTaqzFU/gbU/aIL4vhXs2FZtmzTcprJHfqhoijkC6lg=
Loading

0 comments on commit cb262aa

Please sign in to comment.