mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core V3] add instance listing cli flag (#1079)
* [Core] add instance listing cli flag * Alphabetically sort instance names
This commit is contained in:
parent
1b6065bb46
commit
8dcace4bfd
@ -6,7 +6,8 @@ import sys
|
||||
import discord
|
||||
from redbot.core.bot import Red, ExitCodes
|
||||
from redbot.core.cog_manager import CogManagerUI
|
||||
from redbot.core.data_manager import load_basic_configuration
|
||||
from redbot.core.data_manager import load_basic_configuration, config_file
|
||||
from redbot.core.json_io import JsonIO
|
||||
from redbot.core.global_checks import init_global_checks
|
||||
from redbot.core.events import init_events
|
||||
from redbot.core.sentry_setup import init_sentry_logging
|
||||
@ -81,8 +82,27 @@ async def _get_prefix_and_token(red, indict):
|
||||
indict['enable_sentry'] = await red.db.enable_sentry()
|
||||
|
||||
|
||||
def list_instances():
|
||||
if not config_file.exists():
|
||||
print("No instances have been configured! Configure one "
|
||||
"using `redbot-setup` before trying to run the bot!")
|
||||
sys.exit(1)
|
||||
else:
|
||||
data = JsonIO(config_file)._load_json()
|
||||
text = "Configured Instances:\n\n"
|
||||
for instance_name in sorted(data.keys()):
|
||||
text += "{}\n".format(instance_name)
|
||||
print(text)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def main():
|
||||
cli_flags = parse_cli_flags(sys.argv[1:])
|
||||
if cli_flags.list_instances:
|
||||
list_instances()
|
||||
elif not cli_flags.instance_name:
|
||||
print("Error: No instance name was provided!")
|
||||
sys.exit(1)
|
||||
load_basic_configuration(cli_flags.instance_name)
|
||||
log, sentry_log = init_loggers(cli_flags)
|
||||
description = "Red - Version {}".format(__version__)
|
||||
|
||||
@ -63,6 +63,9 @@ def ask_sentry(red: Red):
|
||||
|
||||
def parse_cli_flags(args):
|
||||
parser = argparse.ArgumentParser(description="Red - Discord Bot")
|
||||
parser.add_argument("--list-instances", action="store_true",
|
||||
help="List all instance names setup "
|
||||
"with 'redbot-setup'")
|
||||
parser.add_argument("--owner", type=int,
|
||||
help="ID of the owner. Only who hosts "
|
||||
"Red should be owner, this has "
|
||||
@ -106,7 +109,7 @@ def parse_cli_flags(args):
|
||||
action="store_true",
|
||||
help="Enables the built-in RPC server. Please read the docs"
|
||||
"prior to enabling this!")
|
||||
parser.add_argument("instance_name",
|
||||
parser.add_argument("instance_name", nargs="?",
|
||||
help="Name of the bot instance created during `redbot-setup`.")
|
||||
|
||||
args = parser.parse_args(args)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user