-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2fed58
commit 242735b
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule Cog.Commands.Role.Rename do | ||
require Cog.Commands.Helpers, as: Helpers | ||
|
||
alias Cog.Repository.Roles | ||
alias Cog.Models.Role | ||
|
||
Helpers.usage """ | ||
Rename a role | ||
USAGE | ||
role rename [FLAGS] <name> <new-name> | ||
ARGS | ||
name The role to rename | ||
new-name The name you want to change to | ||
FLAGS | ||
-h, --help Display this usage info | ||
EXAMPLES | ||
role rename aws-admin cloud-commander | ||
""" | ||
|
||
def rename(%{options: %{"help" => true}}, _args), | ||
do: show_usage | ||
def rename(_req, [old, new]) when is_binary(old) and is_binary(new) do | ||
case Roles.by_name(old) do | ||
%Role{}=role -> | ||
case Roles.rename(role, new) do | ||
{:ok, role} -> | ||
rendered = Cog.V1.RoleView.render("show.json", %{role: role}) | ||
{:ok, "role-rename", Map.put(rendered[:role], :old_name, old)} | ||
{:error, _}=error -> | ||
error | ||
end | ||
nil -> | ||
{:error, {:resource_not_found, "role", old}} | ||
end | ||
end | ||
def rename(_, [_,_]), | ||
do: {:error, :wrong_type} | ||
def rename(_, args) do | ||
error = if length(args) > 2, do: :too_many_args, else: :not_enough_args | ||
{:error, {error, 2}} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Renamed role `{{old_name}}` to `{{name}}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters