Skip to content

Sort options #708

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .cli import CLI
from .completion import get_completions
from .configuration import ENV_TOKEN_NAME
from .help_formatter import SortingHelpFormatter
from .help_pages import (
HELP_TOPICS,
print_help_action,
Expand Down Expand Up @@ -61,6 +62,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
parser = argparse.ArgumentParser(
"linode-cli",
add_help=False,
formatter_class=SortingHelpFormatter,
description="The Linode Command Line Interface.\n\nAliases: lin, linode",
)
parsed, args = register_args(parser).parse_known_args()
Expand Down
2 changes: 2 additions & 0 deletions linodecli/baked/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from linodecli.baked.response import OpenAPIResponse
from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.output.output_handler import OutputHandler
from linodecli.overrides import OUTPUT_OVERRIDES

Expand Down Expand Up @@ -822,6 +823,7 @@ def parse_args(self, args: Any) -> argparse.Namespace:
# build an argparse
parser = argparse.ArgumentParser(
prog=f"linode-cli {self.command} {self.action}",
formatter_class=SortingHelpFormatter,
description=self.summary,
)
for param in self.params:
Expand Down
15 changes: 15 additions & 0 deletions linodecli/help_formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Contains sorting formatter for help menu.
"""

from argparse import HelpFormatter
from operator import attrgetter

class SortingHelpFormatter(HelpFormatter):
"""
The formatter class for help menu.
"""

def add_arguments(self, actions):
actions = sorted(actions, key=attrgetter('option_strings'))
super().add_arguments(actions)
8 changes: 7 additions & 1 deletion linodecli/plugins/firewall-editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rich.table import Table

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import inherit_plugin_args

BOLD = "\033[1m"
Expand Down Expand Up @@ -581,8 +582,13 @@ def call(args, context):
Invokes the Interactive Firewall Plugin
"""
parser = inherit_plugin_args(
argparse.ArgumentParser("firewall-editor", add_help=True)
argparse.ArgumentParser(
"firewall-editor",
add_help=True,
formatter_class=SortingHelpFormatter
)
)

parser.add_argument("firewall_id", help="The ID of the firewall to edit.")

parsed = parser.parse_args(args)
Expand Down
7 changes: 6 additions & 1 deletion linodecli/plugins/get-kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import yaml

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter

PLUGIN_BASE = "linode-cli get-kubeconfig"

Expand All @@ -22,7 +23,11 @@ def call(args, context):
"""
The entrypoint for this plugin
"""
parser = argparse.ArgumentParser(PLUGIN_BASE, add_help=True)
parser = argparse.ArgumentParser(
PLUGIN_BASE,
add_help=True,
formatter_class=SortingHelpFormatter
)

group = parser.add_mutually_exclusive_group()

Expand Down
7 changes: 6 additions & 1 deletion linodecli/plugins/image-upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import inherit_plugin_args

PLUGIN_BASE = "linode-cli image-upload"
Expand Down Expand Up @@ -68,7 +69,11 @@ def call(args, context):
The entrypoint for this plugin
"""
parser = inherit_plugin_args(
argparse.ArgumentParser(PLUGIN_BASE, add_help=True)
argparse.ArgumentParser(
PLUGIN_BASE,
add_help=True,
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
Expand Down
7 changes: 6 additions & 1 deletion linodecli/plugins/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from rich.table import Table

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.helpers import register_debug_arg

PLUGIN_BASE = "linode-cli metadata"
Expand Down Expand Up @@ -184,7 +185,11 @@ def get_metadata_parser():
"""
Builds argparser for Metadata plug-in
"""
parser = ArgumentParser(PLUGIN_BASE, add_help=False)
parser = ArgumentParser(
PLUGIN_BASE,
add_help=False,
formatter_class=SortingHelpFormatter
)

register_debug_arg(parser)

Expand Down
29 changes: 25 additions & 4 deletions linodecli/plugins/obj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from linodecli.configuration import _do_get_request
from linodecli.configuration.helpers import _default_text_input
from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import PluginContext, inherit_plugin_args
from linodecli.plugins.obj.buckets import create_bucket, delete_bucket
from linodecli.plugins.obj.config import (
Expand Down Expand Up @@ -68,7 +69,11 @@ def generate_url(get_client, args, **kwargs): # pylint: disable=unused-argument
"""
Generates a URL to an object
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " signurl"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " signurl",
formatter_class=SortingHelpFormatter)
)

parser.add_argument(
"bucket",
Expand Down Expand Up @@ -119,7 +124,12 @@ def set_acl(get_client, args, **kwargs): # pylint: disable=unused-argument
"""
Modify Access Control List for a Bucket or Objects
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " setacl"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " setacl",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket", metavar="BUCKET", type=str, help="The bucket to modify."
Expand Down Expand Up @@ -182,7 +192,12 @@ def show_usage(get_client, args, **kwargs): # pylint: disable=unused-argument
"""
Shows space used by all buckets in this cluster, and total space
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " du"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " du",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket",
Expand Down Expand Up @@ -287,7 +302,13 @@ def get_obj_args_parser():
"""
Initialize and return the argument parser for the obj plug-in.
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE, add_help=False))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE,
add_help=False,
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"command",
Expand Down
15 changes: 13 additions & 2 deletions linodecli/plugins/obj/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from argparse import ArgumentParser

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import inherit_plugin_args
from linodecli.plugins.obj.config import PLUGIN_BASE
from linodecli.plugins.obj.helpers import _delete_all_objects
Expand All @@ -17,7 +18,12 @@ def create_bucket(
"""
Creates a new bucket
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " mb"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " mb",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"name",
Expand All @@ -41,7 +47,12 @@ def delete_bucket(
"""
Deletes a bucket
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " rb"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " rb",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"name",
Expand Down
17 changes: 15 additions & 2 deletions linodecli/plugins/obj/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rich import print as rprint

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.helpers import register_pagination_args_shared
from linodecli.plugins import inherit_plugin_args
from linodecli.plugins.obj.config import PLUGIN_BASE
Expand All @@ -31,7 +32,13 @@ def list_objects_or_buckets(
"""
Lists buckets or objects
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " ls"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " ls",
formatter_class=SortingHelpFormatter
)
)

register_pagination_args_shared(parser)

parser.add_argument(
Expand Down Expand Up @@ -130,7 +137,13 @@ def list_all_objects(
Lists all objects in all buckets
"""
# this is for printing help when --help is in the args
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " la"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " la",
formatter_class=SortingHelpFormatter
)
)

register_pagination_args_shared(parser)

parsed = parser.parse_args(args)
Expand Down
22 changes: 19 additions & 3 deletions linodecli/plugins/obj/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
pass

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.helpers import expand_globs
from linodecli.plugins import inherit_plugin_args
from linodecli.plugins.obj.config import (
Expand All @@ -36,7 +37,12 @@ def upload_object(
"""
Uploads an object to object storage
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " put"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " put",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"file", metavar="FILE", type=str, nargs="+", help="The files to upload."
Expand Down Expand Up @@ -126,7 +132,12 @@ def get_object(
"""
Retrieves an uploaded object and writes it to a file
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " get"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " get",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket", metavar="BUCKET", type=str, help="The bucket the file is in."
Expand Down Expand Up @@ -201,7 +212,12 @@ def delete_object(
"""
Removes a file from a bucket
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " del"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " del",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket", metavar="BUCKET", type=str, help="The bucket to delete from."
Expand Down
22 changes: 19 additions & 3 deletions linodecli/plugins/obj/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from argparse import ArgumentParser

from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import inherit_plugin_args
from linodecli.plugins.obj.config import BASE_WEBSITE_TEMPLATE, PLUGIN_BASE

Expand All @@ -14,7 +15,12 @@ def enable_static_site(
"""
Turns a bucket into a static website
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " ws-create"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " ws-create",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket",
Expand Down Expand Up @@ -74,7 +80,12 @@ def static_site_info(
"""
Returns info about a configured static site
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " ws-info"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " ws-info",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket",
Expand Down Expand Up @@ -109,7 +120,12 @@ def disable_static_site(
"""
Disables static site for a bucket
"""
parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " du"))
parser = inherit_plugin_args(
ArgumentParser(
PLUGIN_BASE + " du",
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
"bucket",
Expand Down
7 changes: 6 additions & 1 deletion linodecli/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Any, Dict, Optional, Tuple

from linodecli.exit_codes import ExitCodes
from linodecli.help_formatter import SortingHelpFormatter
from linodecli.plugins import inherit_plugin_args


Expand All @@ -33,7 +34,11 @@ def call(args, context): # pylint: disable=too-many-branches
sys.exit(ExitCodes.REQUEST_FAILED)

parser = inherit_plugin_args(
argparse.ArgumentParser("linode-cli ssh", add_help=True)
argparse.ArgumentParser(
"linode-cli ssh",
add_help=True,
formatter_class=SortingHelpFormatter
)
)

parser.add_argument(
Expand Down