Skip to content

Commit

Permalink
Move HelpRequest classes to help package. (#21861)
Browse files Browse the repository at this point in the history
And delete arg_splitter.py, as those were 
the last remaining bits of code in that file.
  • Loading branch information
benjyw authored Jan 22, 2025
1 parent 7cab9e3 commit 77aa4d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 62 deletions.
14 changes: 9 additions & 5 deletions src/python/pants/goal/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
from pants.engine.unions import UnionMembership
from pants.goal.builtin_goal import BuiltinGoal
from pants.help.help_info_extracter import HelpInfoExtracter
from pants.help.help_printer import HelpPrinter
from pants.init.engine_initializer import GraphSession
from pants.option.arg_splitter import (
NO_GOAL_NAME,
UNKNOWN_GOAL_NAME,
from pants.help.help_printer import (
AllHelp,
HelpPrinter,
HelpRequest,
NoGoalHelp,
ThingHelp,
UnknownGoalHelp,
VersionHelp,
)
from pants.init.engine_initializer import GraphSession
from pants.option.options import Options

# These are the names for the built in goals to print help message when there is no goal, or any
# unknown goals respectively. They begin with underlines to exclude them from the list of goals in
# the goal help output.
NO_GOAL_NAME = "__no_goal"
UNKNOWN_GOAL_NAME = "__unknown_goal"


class HelpBuiltinGoalBase(BuiltinGoal):
def run(
Expand Down
42 changes: 34 additions & 8 deletions src/python/pants/help/help_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import json
import re
import textwrap
from abc import ABC
from dataclasses import dataclass
from itertools import cycle
from typing import Callable, Dict, Iterable, List, Literal, Optional, Set, Tuple, cast

Expand All @@ -13,19 +15,43 @@
from pants.help.help_info_extracter import AllHelpInfo, HelpJSONEncoder
from pants.help.help_tools import ToolHelpInfo
from pants.help.maybe_color import MaybeColor
from pants.option.arg_splitter import (
AllHelp,
HelpRequest,
NoGoalHelp,
ThingHelp,
UnknownGoalHelp,
VersionHelp,
)
from pants.option.scope import GLOBAL_SCOPE
from pants.util.docutil import bin_name, terminal_width
from pants.util.strutil import first_paragraph, hard_wrap, pluralize, softwrap


class HelpRequest(ABC):
"""Represents an implicit or explicit request for help by the user."""


@dataclass(frozen=True)
class ThingHelp(HelpRequest):
"""The user requested help on one or more things: e.g., an options scope or a target type."""

advanced: bool = False
things: tuple[str, ...] = ()
likely_specs: tuple[str, ...] = ()


class VersionHelp(HelpRequest):
"""The user asked for the version of this instance of pants."""


class AllHelp(HelpRequest):
"""The user requested a dump of all help info."""


@dataclass(frozen=True)
class UnknownGoalHelp(HelpRequest):
"""The user specified an unknown goal (or task)."""

unknown_goals: tuple[str, ...]


class NoGoalHelp(HelpRequest):
"""The user specified no goals."""


class HelpPrinter(MaybeColor):
"""Prints general and goal-related help to the console."""

Expand Down
49 changes: 0 additions & 49 deletions src/python/pants/option/arg_splitter.py

This file was deleted.

0 comments on commit 77aa4d8

Please sign in to comment.