Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenient aliases for allow/deny commands #935

Merged
merged 4 commits into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
UNRELEASED / 2022-04-??
==================
* Add "block" and "revoke" as aliases of the "deny" command (#935)
* Add "permit" and "grant" as aliases of the "allow" command (#935)

2.31.0 / 2022-03-26
==================
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/cmd_allow.go
Expand Up @@ -8,10 +8,11 @@ import (

// CmdAllow is `direnv allow [PATH_TO_RC]`
var CmdAllow = &Cmd{
Name: "allow",
Desc: "Grants direnv to load the given .envrc or .env",
Args: []string{"[PATH_TO_RC]"},
Action: actionWithConfig(cmdAllowAction),
Name: "allow",
Desc: "Grants direnv permission to load the given .envrc or .env file.",
Args: []string{"[PATH_TO_RC]"},
Aliases: []string{"permit", "grant"},
Action: actionWithConfig(cmdAllowAction),
}

var migrationMessage = `
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/cmd_deny.go
Expand Up @@ -8,10 +8,11 @@ import (

// CmdDeny is `direnv deny [PATH_TO_RC]`
var CmdDeny = &Cmd{
Name: "deny",
Desc: "Revokes the authorization of a given .envrc or .env",
Args: []string{"[PATH_TO_RC]"},
Action: actionWithConfig(cmdDenyAction),
Name: "block",
Desc: "Revokes the authorization of a given .envrc or .env file.",
Args: []string{"[PATH_TO_RC]"},
Aliases: []string{"deny", "revoke"},
Action: actionWithConfig(cmdDenyAction),
}

func cmdDenyAction(env Env, args []string, config *Config) (err error) {
Expand Down
8 changes: 7 additions & 1 deletion internal/cmd/cmd_help.go
Expand Up @@ -29,7 +29,13 @@ Available commands
fmt.Printf("*%s%s:\n %s\n", cmd.Name, opts, cmd.Desc)
}
} else {
fmt.Printf("%s%s:\n %s\n", cmd.Name, opts, cmd.Desc)
fmt.Printf("%s%s:\n", cmd.Name, opts)
for _, alias := range cmd.Aliases {
if alias[0:1] != "-" {
fmt.Printf("%s%s:\n", alias, opts)
}
}
fmt.Printf(" %s\n", cmd.Desc)
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/direnv-test-common.sh
Expand Up @@ -247,6 +247,15 @@ test_start "skip-env"
test -z "${SKIPPED}"
test_stop

test_start "aliases"
direnv deny
# check that allow/deny aliases work
direnv permit && direnv_eval && test -n "${HELLO}"
direnv block && direnv_eval && test -z "${HELLO}"
direnv grant && direnv_eval && test -n "${HELLO}"
direnv revoke && direnv_eval && test -z "${HELLO}"
test_stop

# Context: foo/bar is a symlink to ../baz. foo/ contains and .envrc file
# BUG: foo/bar is resolved in the .envrc execution context and so can't find
# the .envrc file.
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/aliases/.envrc
@@ -0,0 +1 @@
export HELLO=world