diff --git a/python/ray/scripts/scripts.py b/python/ray/scripts/scripts.py index 4dd9e049834b..9a9a9e57d89f 100644 --- a/python/ray/scripts/scripts.py +++ b/python/ray/scripts/scripts.py @@ -142,7 +142,53 @@ def _check_ray_version(gcs_client): ) -@click.group() +class RayCLI(click.Group): + """Custom click.Group that groups observability commands (State CLI commands) in help output. + + This overrides format_commands to split subcommands into "Observability" + and "Commands" sections for better readability of ray --help output. + """ + + def format_commands(self, ctx, formatter): + commands = [] + for subcommand in self.list_commands(ctx): + cmd = self.get_command(ctx, subcommand) + if cmd is None: + continue + if cmd.hidden: + continue + commands.append((subcommand, cmd)) + + if len(commands): + limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands) + + observability_commands = [] + other_commands = [] + + observability_names = { + "summary", + "list", + "get", + "logs", + } + + for subcommand, cmd in commands: + help = cmd.get_short_help_str(limit) + if subcommand in observability_names: + observability_commands.append((subcommand, help)) + else: + other_commands.append((subcommand, help)) + + if other_commands: + with formatter.section("Commands"): + formatter.write_dl(other_commands) + + if observability_commands: + with formatter.section("Observability"): + formatter.write_dl(observability_commands) + + +@click.group(cls=RayCLI) @click.option( "--logging-level", required=False,