Skip to content

Commit

Permalink
align all ls command options (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan authored Jun 6, 2023
1 parent de35f9b commit d788b80
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.D/2995.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Align all `ls` command options.
31 changes: 25 additions & 6 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,8 @@ neuro blob lsbucket [OPTIONS]
Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\--all-orgs_|Show buckets in all orgs.|
|_\--all-projects_|Show buckets in all projects.|
|_--cluster CLUSTER_|Look on a specified cluster \(the current cluster by default).|
|_\--full-uri_|Output full bucket URI.|
|_\--long-format_|Output all info about bucket.|
Expand Down Expand Up @@ -2179,10 +2181,13 @@ neuro disk ls [OPTIONS]
Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\--all-orgs_|Show disks in all orgs.|
|_\--all-projects_|Show disks in all projects.|
|_--cluster CLUSTER_|Look on a specified cluster \(the current cluster by default).|
|_\--full-uri_|Output full disk URI.|
|_\--long-format_|Output all info about disk.|
|_--project PROJECT_|Look on a specified project \(all projects in current cluster by default).|
|_--org ORG_|Look on a specified org \(the current org by default).|
|_--project PROJECT_|Look on a specified project \(the current project by default).|



Expand Down Expand Up @@ -2282,11 +2287,14 @@ neuro image ls [OPTIONS]
Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\--all-orgs_|Show images in all orgs.|
|_\--all-projects_|Show images in all projects.|
|_--cluster CLUSTER_|Show images on a specified cluster \(the current cluster by default).|
|_-l_|List in long format.|
|_\--full-uri_|Output full image URI.|
|_\-n, --name PATTERN_|Filter out images by name regex.|
|_--project PROJECT_|Filter out images by project \(multiple option, all projects in current cluster by default).|
|_--org ORG_|Filter out images by org \(multiple option, the current org by default).|
|_--project PROJECT_|Filter out images by project \(multiple option, the current project by default).|



Expand Down Expand Up @@ -2660,14 +2668,17 @@ Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\-a, --all_|Show all jobs regardless the status.|
|_\--all-orgs_|Show jobs in all orgs.|
|_\--all-projects_|Show jobs in all projects.|
|_--cluster CLUSTER_|Show jobs on a specified cluster \(the current cluster by default).|
|_\-d, --description DESCRIPTION_|Filter out jobs by description \(exact match).|
|_--distinct_|Show only first job if names are same.|
|_--format COLUMNS_|Output table format, see "neuro help ps\-format" for more info about the format specification. The default can be changed using the job.ps-format configuration variable documented in "neuro help user-config"|
|_\--full-uri_|Output full image URI.|
|_\-n, --name NAME_|Filter out jobs by name.|
|_--org ORG_|Filter out jobs by org name \(multiple option, the current org by default).|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user.|
|_\-p, --project PROJECT_|Filter out jobs by project name \(multiple option).|
|_\-p, --project PROJECT_|Filter out jobs by project name \(multiple option, the current project by default).|
|_\--recent-first / --recent-last_|Show newer jobs first or last|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-s, --status \[pending | suspended | running | succeeded | failed | cancelled]_|Filter out jobs by status \(multiple option).|
Expand Down Expand Up @@ -2947,8 +2958,10 @@ neuro secret ls [OPTIONS]
Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\--all-orgs_|Show secrets in all orgs.|
|_\--all-projects_|Show secrets in all projects.|
|_--cluster CLUSTER_|Look on a specified cluster \(the current cluster by default).|
|_\--full-uri_|Output full disk URI.|
|_\--full-uri_|Output full secret URI.|
|_--org ORG_|Look on a specified org \(the current org by default).|
|_--project PROJECT_|Look on a specified project \(the current project by default).|

Expand Down Expand Up @@ -3508,11 +3521,14 @@ neuro images [OPTIONS]
Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\--all-orgs_|Show images in all orgs.|
|_\--all-projects_|Show images in all projects.|
|_--cluster CLUSTER_|Show images on a specified cluster \(the current cluster by default).|
|_-l_|List in long format.|
|_\--full-uri_|Output full image URI.|
|_\-n, --name PATTERN_|Filter out images by name regex.|
|_--project PROJECT_|Filter out images by project \(multiple option, all projects in current cluster by default).|
|_--org ORG_|Filter out images by org \(multiple option, the current org by default).|
|_--project PROJECT_|Filter out images by project \(multiple option, the current project by default).|



Expand Down Expand Up @@ -3752,14 +3768,17 @@ Name | Description|
|----|------------|
|_--help_|Show this message and exit.|
|_\-a, --all_|Show all jobs regardless the status.|
|_\--all-orgs_|Show jobs in all orgs.|
|_\--all-projects_|Show jobs in all projects.|
|_--cluster CLUSTER_|Show jobs on a specified cluster \(the current cluster by default).|
|_\-d, --description DESCRIPTION_|Filter out jobs by description \(exact match).|
|_--distinct_|Show only first job if names are same.|
|_--format COLUMNS_|Output table format, see "neuro help ps\-format" for more info about the format specification. The default can be changed using the job.ps-format configuration variable documented in "neuro help user-config"|
|_\--full-uri_|Output full image URI.|
|_\-n, --name NAME_|Filter out jobs by name.|
|_--org ORG_|Filter out jobs by org name \(multiple option, the current org by default).|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user.|
|_\-p, --project PROJECT_|Filter out jobs by project name \(multiple option).|
|_\-p, --project PROJECT_|Filter out jobs by project name \(multiple option, the current project by default).|
|_\--recent-first / --recent-last_|Show newer jobs first or last|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-s, --status \[pending | suspended | running | succeeded | failed | cancelled]_|Filter out jobs by status \(multiple option).|
Expand Down
2 changes: 2 additions & 0 deletions neuro-cli/docs/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ List buckets.
| Name | Description |
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _--all-orgs_ | Show buckets in all orgs. |
| _--all-projects_ | Show buckets in all projects. |
| _--cluster CLUSTER_ | Look on a specified cluster \(the current cluster by default\). |
| _--full-uri_ | Output full bucket URI. |
| _--long-format_ | Output all info about bucket. |
Expand Down
5 changes: 4 additions & 1 deletion neuro-cli/docs/disk.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ List disks.
| Name | Description |
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _--all-orgs_ | Show disks in all orgs. |
| _--all-projects_ | Show disks in all projects. |
| _--cluster CLUSTER_ | Look on a specified cluster \(the current cluster by default\). |
| _--full-uri_ | Output full disk URI. |
| _--long-format_ | Output all info about disk. |
| _--project PROJECT_ | Look on a specified project \(all projects in current cluster by default\). |
| _--org ORG_ | Look on a specified org \(the current org by default\). |
| _--project PROJECT_ | Look on a specified project \(the current project by default\). |



Expand Down
5 changes: 4 additions & 1 deletion neuro-cli/docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ List images.
| Name | Description |
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _--all-orgs_ | Show images in all orgs. |
| _--all-projects_ | Show images in all projects. |
| _--cluster CLUSTER_ | Show images on a specified cluster \(the current cluster by default\). |
| _-l_ | List in long format. |
| _--full-uri_ | Output full image URI. |
| _-n, --name PATTERN_ | Filter out images by name regex. |
| _--project PROJECT_ | Filter out images by project \(multiple option, all projects in current cluster by default\). |
| _--org ORG_ | Filter out images by org \(multiple option, the current org by default\). |
| _--project PROJECT_ | Filter out images by project \(multiple option, the current project by default\). |



Expand Down
5 changes: 4 additions & 1 deletion neuro-cli/docs/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,17 @@ $ neuro ps -t tag1 -t tag2
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _-a, --all_ | Show all jobs regardless the status. |
| _--all-orgs_ | Show jobs in all orgs. |
| _--all-projects_ | Show jobs in all projects. |
| _--cluster CLUSTER_ | Show jobs on a specified cluster \(the current cluster by default\). |
| _-d, --description DESCRIPTION_ | Filter out jobs by description \(exact match\). |
| _--distinct_ | Show only first job if names are same. |
| _--format COLUMNS_ | Output table format, see "neuro help ps-format" for more info about the format specification. The default can be changed using the job.ps-format configuration variable documented in "neuro help user-config" |
| _--full-uri_ | Output full image URI. |
| _-n, --name NAME_ | Filter out jobs by name. |
| _--org ORG_ | Filter out jobs by org name \(multiple option, the current org by default\). |
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. |
| _-p, --project PROJECT_ | Filter out jobs by project name \(multiple option\). |
| _-p, --project PROJECT_ | Filter out jobs by project name \(multiple option, the current project by default\). |
| _--recent-first / --recent-last_ | Show newer jobs first or last |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-s, --status \[pending | suspended | running | succeeded | failed | cancelled\]_ | Filter out jobs by status \(multiple option\). |
Expand Down
4 changes: 3 additions & 1 deletion neuro-cli/docs/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ List secrets.
| Name | Description |
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _--all-orgs_ | Show secrets in all orgs. |
| _--all-projects_ | Show secrets in all projects. |
| _--cluster CLUSTER_ | Look on a specified cluster \(the current cluster by default\). |
| _--full-uri_ | Output full disk URI. |
| _--full-uri_ | Output full secret URI. |
| _--org ORG_ | Look on a specified org \(the current org by default\). |
| _--project PROJECT_ | Look on a specified project \(the current project by default\). |

Expand Down
10 changes: 8 additions & 2 deletions neuro-cli/docs/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ List images.
| Name | Description |
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _--all-orgs_ | Show images in all orgs. |
| _--all-projects_ | Show images in all projects. |
| _--cluster CLUSTER_ | Show images on a specified cluster \(the current cluster by default\). |
| _-l_ | List in long format. |
| _--full-uri_ | Output full image URI. |
| _-n, --name PATTERN_ | Filter out images by name regex. |
| _--project PROJECT_ | Filter out images by project \(multiple option, all projects in current cluster by default\). |
| _--org ORG_ | Filter out images by org \(multiple option, the current org by default\). |
| _--project PROJECT_ | Filter out images by project \(multiple option, the current project by default\). |



Expand Down Expand Up @@ -453,14 +456,17 @@ $ neuro ps -t tag1 -t tag2
| :--- | :--- |
| _--help_ | Show this message and exit. |
| _-a, --all_ | Show all jobs regardless the status. |
| _--all-orgs_ | Show jobs in all orgs. |
| _--all-projects_ | Show jobs in all projects. |
| _--cluster CLUSTER_ | Show jobs on a specified cluster \(the current cluster by default\). |
| _-d, --description DESCRIPTION_ | Filter out jobs by description \(exact match\). |
| _--distinct_ | Show only first job if names are same. |
| _--format COLUMNS_ | Output table format, see "neuro help ps-format" for more info about the format specification. The default can be changed using the job.ps-format configuration variable documented in "neuro help user-config" |
| _--full-uri_ | Output full image URI. |
| _-n, --name NAME_ | Filter out jobs by name. |
| _--org ORG_ | Filter out jobs by org name \(multiple option, the current org by default\). |
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. |
| _-p, --project PROJECT_ | Filter out jobs by project name \(multiple option\). |
| _-p, --project PROJECT_ | Filter out jobs by project name \(multiple option, the current project by default\). |
| _--recent-first / --recent-last_ | Show newer jobs first or last |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-s, --status \[pending | suspended | running | succeeded | failed | cancelled\]_ | Filter out jobs by status \(multiple option\). |
Expand Down
52 changes: 32 additions & 20 deletions neuro-cli/src/neuro_cli/blob_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from yarl import URL

from neuro_sdk import (
ORG_NAME_SENTINEL,
Bucket,
Client,
FileFilter,
Expand All @@ -16,7 +17,7 @@
ResourceNotFound,
)

from neuro_cli.click_types import (
from .click_types import (
BUCKET,
BUCKET_CREDENTIAL,
BUCKET_NAME,
Expand All @@ -25,40 +26,36 @@
PROJECT,
PlatformURIType,
)
from neuro_cli.formatters.bucket_credentials import (
from .const import EX_OSFILE
from .formatters.blob_storage import (
BaseBlobFormatter,
LongBlobFormatter,
SimpleBlobFormatter,
)
from .formatters.bucket_credentials import (
BaseBucketCredentialsFormatter,
BucketCredentialFormatter,
BucketCredentialsFormatter,
SimpleBucketCredentialsFormatter,
)
from neuro_cli.formatters.buckets import (
from .formatters.buckets import (
BaseBucketsFormatter,
BucketFormatter,
BucketsFormatter,
SimpleBucketsFormatter,
)
from neuro_cli.formatters.utils import (
URIFormatter,
get_datetime_formatter,
uri_formatter,
)
from neuro_cli.parse_utils import parse_timedelta
from neuro_cli.utils import format_size, parse_org_name

from .const import EX_OSFILE
from .formatters.blob_storage import (
BaseBlobFormatter,
LongBlobFormatter,
SimpleBlobFormatter,
)
from .formatters.storage import DeleteProgress, create_storage_progress, get_painter
from .formatters.utils import URIFormatter, get_datetime_formatter, uri_formatter
from .parse_utils import parse_timedelta
from .root import Root
from .storage import calc_filters, calc_ignore_file_names, filter_option
from .utils import (
argument,
command,
format_size,
group,
option,
parse_org_name,
resolve_bucket,
resolve_bucket_credential,
)
Expand Down Expand Up @@ -87,11 +84,15 @@ def blob_storage() -> None:
type=ORG,
help="Look on a specified org (the current org by default).",
)
@option("--all-orgs", is_flag=True, default=False, help="Show buckets in all orgs.")
@option(
"--project",
type=PROJECT,
help="Look on a specified project (the current project by default).",
)
@option(
"--all-projects", is_flag=True, default=False, help="Show buckets in all projects."
)
@option("--full-uri", is_flag=True, help="Output full bucket URI.")
@option("--long-format", is_flag=True, help="Output all info about bucket.")
async def lsbucket(
Expand All @@ -100,7 +101,9 @@ async def lsbucket(
long_format: bool,
cluster: Optional[str],
org: Optional[str],
all_orgs: bool,
project: Optional[str],
all_projects: bool,
) -> None:
"""
List buckets.
Expand All @@ -113,7 +116,7 @@ async def lsbucket(
else:
uri_fmtr = uri_formatter(
project_name=root.client.config.project_name_or_raise,
cluster_name=cluster or root.client.cluster_name,
cluster_name=root.client.cluster_name,
org_name=root.client.config.org_name,
)
buckets_fmtr = BucketsFormatter(
Expand All @@ -122,13 +125,22 @@ async def lsbucket(
long_format=long_format,
)

org_name = parse_org_name(org, root)
if all_orgs:
org_name = ORG_NAME_SENTINEL
else:
org_name = parse_org_name(org, root) # type: ignore

if all_projects:
project_name = None
else:
project_name = project or root.client.config.project_name_or_raise

buckets = []
with root.status("Fetching buckets") as status:
async with root.client.buckets.list(
cluster_name=cluster,
org_name=org_name,
project_name=project or root.client.config.project_name_or_raise,
project_name=project_name,
) as it:
async for bucket in it:
buckets.append(bucket)
Expand Down
Loading

0 comments on commit d788b80

Please sign in to comment.