mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Require config files to be explicitly created (#1040)
The behaviour of creating the config file if it's missing while convenient causes confusion and problems when the tools are run in the wrong folder. They end up creating a shadow installation and misdirect the user with nonsensical error messages, instead pointing to the real problem which is that the tool can't find the configuration needed to actually run. Require a config file to be present at startup and refuse to run if this file is missing. To support the odd use-case of creating the config when missing a --create-config flag is added. To conveniently generate a config file to edit out from the "config create" command is added.
This commit is contained in:
1 parent
5df5af7ca8
commit
2c52c265cf
15 files changed
+249
-75
No files matched your search
+11
-1
@@ -17,9 +17,12 @@ Common options:
|
||||
See the `plugin` command for managing this list.
|
||||
|
||||
* `--config <file>` JSON file to use for storing configuration for ctl.
|
||||
Defaults to `config-ctl.json` and will be created if it does not exist.
|
||||
Defaults to `config-ctl.json` and is required for operation.
|
||||
See the `config` command for inspecting and modifying the configuration.
|
||||
|
||||
* `--create-config` If the config file is missing, create a new one and carry on instead of exiting with an error.
|
||||
Alternative to the `config create` command.
|
||||
|
||||
|
||||
### `plugin <command>`
|
||||
|
||||
@@ -76,6 +79,13 @@ Manage the ctl configuration.
|
||||
This allows setting the url and token to the controller to manage.
|
||||
|
||||
|
||||
#### `config create`
|
||||
|
||||
Create a new config file with the default options inserted into if it doesn't already exist.
|
||||
|
||||
See also the `--create-config` option.
|
||||
|
||||
|
||||
#### `config set <config-entry> [value]`
|
||||
|
||||
Set a config entry to the given value.
|
||||
|
||||
+13
-21
@@ -128,6 +128,8 @@ interface CtlArguments {
|
||||
logLevel: keyof typeof levels,
|
||||
config: string,
|
||||
pluginList: string,
|
||||
bypassLockFile: boolean,
|
||||
createConfig: boolean,
|
||||
}
|
||||
|
||||
interface InitializeParameters {
|
||||
@@ -170,6 +172,12 @@ export async function initialize(
|
||||
defaultDescription: "auto",
|
||||
type: "string",
|
||||
})
|
||||
.option("create-config", {
|
||||
nargs: 0,
|
||||
describe: "Create config file if it does not exist",
|
||||
default: false,
|
||||
type: "boolean",
|
||||
})
|
||||
.option("plugin-list", {
|
||||
nargs: 1,
|
||||
describe: "File containing list of plugins available with their install path",
|
||||
@@ -222,27 +230,11 @@ export async function initialize(
|
||||
.parse(argv) as CtlArguments
|
||||
;
|
||||
|
||||
const ctlConfigPath = args.config;
|
||||
const ctlConfigLockPath = `${ctlConfigPath}.lock`;
|
||||
if (args.bypassLockFile) {
|
||||
await fs.unlink(ctlConfigLockPath).catch(() => {}); // ignore error, file might not exist
|
||||
}
|
||||
|
||||
let ctlConfig;
|
||||
const ctlConfigLock = new lib.LockFile(ctlConfigLockPath);
|
||||
logger.verbose(`Loading config from ${ctlConfigPath}`);
|
||||
try {
|
||||
ctlConfig = await lib.CtlConfig.fromFile("control", ctlConfigPath);
|
||||
|
||||
} catch (err: any) {
|
||||
if (err.code === "ENOENT") {
|
||||
logger.verbose("Config not found, initializing new config");
|
||||
ctlConfig = new lib.CtlConfig("control", undefined, ctlConfigPath);
|
||||
|
||||
} else {
|
||||
throw new lib.StartupError(`Failed to load ${args.config}: ${err.stack ?? err.message ?? err}`);
|
||||
}
|
||||
}
|
||||
const [ctlConfig, ctlConfigLock] = await lib.loadConfigFromArgs(
|
||||
args,
|
||||
lib.CtlConfig,
|
||||
"control",
|
||||
);
|
||||
|
||||
if (args._.length === 0) {
|
||||
parser.showHelp();
|
||||
|
||||
Reference in new issue
Block a user