[V3] --token and --no-instance flags (#1872)

* Ability to run Red with token without instance

* --no-instance flag

* Reformatted cli with black

* Fix changes requested by @Tobotimus

- Use "system reboot" to be clearer
- save_default_config renamed to create_temp_config
- More documentation for the create_temp_config function

* Update create_temp_config call

* Fix up imports
This commit is contained in:
El Laggron
2018-06-25 11:25:23 +02:00
committed by Toby Harradine
parent c1bcca4432
commit ad27607ccc
3 changed files with 45 additions and 2 deletions

View File

@@ -138,6 +138,16 @@ 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("--token", type=str, help="Run Red with the given token.")
parser.add_argument(
"--no-instance",
action="store_true",
help=(
"Run Red without any existing instance. "
"The data will be saved under a temporary folder "
"and deleted on next system restart."
),
)
parser.add_argument(
"instance_name", nargs="?", help="Name of the bot instance created during `redbot-setup`."
)

View File

@@ -2,15 +2,18 @@ import sys
import os
from pathlib import Path
from typing import List
from copy import deepcopy
import hashlib
import shutil
import logging
import appdirs
import tempfile
from .json_io import JsonIO
__all__ = [
"create_temp_config",
"load_basic_configuration",
"cog_data_path",
"core_data_path",
@@ -39,6 +42,26 @@ if not config_dir:
config_file = config_dir / "config.json"
def create_temp_config():
"""
Creates a default instance for Red, so it can be ran
without creating an instance.
.. warning:: The data of this instance will be removed
on next system restart.
"""
name = "temporary_red"
default_dirs = deepcopy(basic_config_default)
default_dirs["DATA_PATH"] = tempfile.mkdtemp()
default_dirs["STORAGE_TYPE"] = "JSON"
default_dirs["STORAGE_DETAILS"] = {}
config = JsonIO(config_file)._load_json()
config[name] = default_dirs
JsonIO(config_file)._save_json(config)
def load_basic_configuration(instance_name_: str):
"""Loads the basic bootstrap configuration necessary for `Config`
to know where to store or look for data.