-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(organization): adds organization command in the CLI
This commit introduces the organization command in the CLI that allows you to list the organizations that you are a part of and let's you switch between organiztions as well. Usage: python -m riocli organization [OPTIONS] COMMAND [ARGS]... Organizations in rapyuta.io Options: --help Show this message and exit. Commands: list List all the organizations that you are a part of select Sets the current organization to the one provided in the... BREAKING CHANGE: This commit modifies the login command options. Commands with the following structure will break rio auth login --email <> --password <> --project <> --no-interactive
- Loading branch information
1 parent
5761c25
commit 5a5f599
Showing
6 changed files
with
194 additions
and
16 deletions.
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
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,35 @@ | ||
# Copyright 2023 Rapyuta Robotics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import click | ||
from click_help_colors import HelpColorsGroup | ||
|
||
from riocli.organization.list import list_organizations | ||
from riocli.organization.select import select_organization | ||
|
||
|
||
@click.group( | ||
invoke_without_command=False, | ||
cls=HelpColorsGroup, | ||
help_headers_color='yellow', | ||
help_options_color='green', | ||
) | ||
def organization() -> None: | ||
""" | ||
Organizations in rapyuta.io | ||
""" | ||
pass | ||
|
||
|
||
organization.add_command(list_organizations) | ||
organization.add_command(select_organization) |
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,57 @@ | ||
# Copyright 2023 Rapyuta Robotics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import click | ||
|
||
from riocli.config import new_client | ||
from riocli.utils import tabulate_data | ||
|
||
|
||
@click.command('list') | ||
@click.pass_context | ||
def list_organizations(ctx: click.Context) -> None: | ||
""" | ||
List all the organizations that you are a part of | ||
Example: | ||
rio organization list | ||
""" | ||
try: | ||
client = new_client(with_project=False) | ||
organizations = client.get_user_organizations() | ||
current = ctx.obj.data['organization_id'] | ||
print_organizations(organizations, current) | ||
except Exception as e: | ||
click.secho(str(e), fg='red') | ||
raise SystemExit(1) from e | ||
|
||
|
||
def print_organizations(organizations, current): | ||
organizations = sorted(organizations, key=lambda o: o.name) | ||
|
||
headers = ["Name", "GUID", "Creator", "Short GUID"] | ||
|
||
data = [] | ||
for org in organizations: | ||
fg = None | ||
if org.guid == current: | ||
fg = 'green' | ||
data.append([ | ||
click.style(v, fg=fg) | ||
for v in (org.name, org.guid, | ||
org.creator, org.short_guid) | ||
]) | ||
|
||
tabulate_data(data, headers) |
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,46 @@ | ||
# Copyright 2023 Rapyuta Robotics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import click | ||
|
||
from riocli.auth.util import select_project | ||
from riocli.utils.context import get_root_context | ||
from riocli.project.util import name_to_organization_guid | ||
|
||
|
||
@click.command('select') | ||
@click.argument('organization-name', type=str) | ||
@click.pass_context | ||
@name_to_organization_guid | ||
def select_organization(ctx: click.Context, organization_name: str, organization_guid: str) -> None: | ||
""" | ||
Sets the current organization to the one provided | ||
in the argument and prompts you to select a new project | ||
in the changed organization | ||
Example: | ||
rio organization select other-org | ||
""" | ||
ctx = get_root_context(ctx) | ||
|
||
if ctx.obj.data['organization_id'] == organization_guid: | ||
click.secho("You are already in the '{}' organization".format(organization_name), fg='green') | ||
return | ||
|
||
ctx.obj.data['organization_id'] = organization_guid | ||
ctx.obj.data['organization_name'] = organization_name | ||
|
||
select_project(ctx.obj, organization=organization_guid) | ||
|
||
ctx.obj.save() |