-
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.
Adding new maintenance command type to address bootstrap issues with …
…help commands
- Loading branch information
Jordan Mance
committed
Sep 19, 2021
1 parent
f2b26ce
commit dd8f891
Showing
10 changed files
with
96 additions
and
26 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 |
---|---|---|
@@ -1,38 +1,30 @@ | ||
from figcli.commands.factory import Factory | ||
from figcli.commands.figgy_context import FiggyContext | ||
from figcli.commands.help.configure import Configure | ||
from figcli.commands.help.login import Login | ||
from figcli.commands.help.upgrade import Upgrade | ||
from figcli.commands.help.version import Version | ||
from figcli.commands.help_context import HelpContext | ||
from figcli.commands.help.configure import Configure | ||
from figcli.config import * | ||
from figcli.svcs.config import ConfigService | ||
from figcli.svcs.setup import FiggySetup | ||
from figcli.utils.utils import Utils, CollectionUtils | ||
|
||
|
||
class HelpFactory(Factory): | ||
def __init__(self, command: CliCommand, context: HelpContext, figgy_context: FiggyContext, config: ConfigService): | ||
def __init__(self, command: CliCommand, context: HelpContext, figgy_context: FiggyContext): | ||
self._command = command | ||
self._context = context | ||
self._figgy_context = figgy_context | ||
self._options = context.options | ||
self._utils = Utils(False) | ||
self._setup: FiggySetup = FiggySetup(self._figgy_context) | ||
self._config: ConfigService = config | ||
|
||
def instance(self): | ||
return self.get(self._command) | ||
|
||
def get(self, command: CliCommand): | ||
if configure in self._options: | ||
return Configure(self._context, self._setup) | ||
elif version in self._options: | ||
return Version(self._context, self._config) | ||
elif command == login or command == sandbox: | ||
return Login(self._context, self._setup, self._figgy_context) | ||
elif upgrade in self._options: | ||
return Upgrade(self._context, self._config) | ||
else: | ||
self._utils.error_exit(f"{command.name} is not a valid command. You must select from: " | ||
f"[{CollectionUtils.printable_set(help_commands)}]. Try using --help for more info.") |
Empty file.
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,22 @@ | ||
from typing import Optional, List, Set | ||
|
||
from figcli.commands.command_context import CommandContext | ||
from figcli.models.defaults.defaults import CLIDefaults, CliCommand | ||
from figcli.models.role import Role | ||
from figgy.models.run_env import RunEnv | ||
|
||
|
||
class MaintenanceContext(CommandContext): | ||
""" | ||
Contextual information for HelpCommands, including _what_ command resources were passed in. Help commands | ||
often don't have standard "resource" or "command" blocks, instead they may ONLY have --optional parameters | ||
""" | ||
def __init__(self, resource: Optional[CliCommand], command: Optional[CliCommand], | ||
options: Optional[Set[CliCommand]], run_env: Optional[RunEnv], defaults: Optional[CLIDefaults], | ||
role: Optional[Role]): | ||
super().__init__(run_env, resource, defaults=defaults) | ||
|
||
self.resource = resource | ||
self.command = command | ||
self.options = options | ||
self.role = role |
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,32 @@ | ||
from figcli.commands.factory import Factory | ||
from figcli.commands.figgy_context import FiggyContext | ||
from figcli.commands.help.upgrade import Upgrade | ||
from figcli.commands.help.version import Version | ||
from figcli.commands.maintenance_context import MaintenanceContext | ||
from figcli.config import * | ||
from figcli.svcs.config import ConfigService | ||
from figcli.svcs.setup import FiggySetup | ||
from figcli.utils.utils import Utils, CollectionUtils | ||
|
||
|
||
class MaintenanceFactory(Factory): | ||
def __init__(self, command: CliCommand, context: MaintenanceContext, figgy_context: FiggyContext, config: ConfigService): | ||
self._command = command | ||
self._context = context | ||
self._figgy_context = figgy_context | ||
self._options = context.options | ||
self._utils = Utils(False) | ||
self._setup: FiggySetup = FiggySetup(self._figgy_context) | ||
self._config: ConfigService = config | ||
|
||
def instance(self): | ||
return self.get(self._command) | ||
|
||
def get(self, command: CliCommand): | ||
if version in self._options: | ||
return Version(self._context, self._config) | ||
elif upgrade in self._options: | ||
return Upgrade(self._context, self._config) | ||
else: | ||
self._utils.error_exit(f"{command.name} is not a valid command. You must select from: " | ||
f"[{CollectionUtils.printable_set(help_commands)}]. Try using --help for more info.") |
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,13 @@ | ||
from abc import ABC | ||
|
||
from figcli.commands.maintenance_context import MaintenanceContext | ||
from figcli.commands.types.command import Command | ||
|
||
|
||
class MaintenanceCommand(Command, ABC): | ||
""" | ||
Help command class to support some commands that may not have a resource or specific command selected | ||
""" | ||
|
||
def __init__(self, command_type: frozenset, colors_enabled: bool, context: MaintenanceContext): | ||
super().__init__(command_type, colors_enabled, context) |
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