diff --git a/docs/index.md b/docs/index.md index 8c7290a..e69f17b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,7 +16,9 @@ poetry run kci-dev ## Configuration -kci-dev uses a configuration file .kci-dev.toml in the program directory. +kci-dev uses a configuration file .kci-dev.toml in the current program directory +or global configuration directory, in user's home directory/.config/kci-dev.toml. + ```toml default_instance="local" diff --git a/kcidev/libs/common.py b/kcidev/libs/common.py index ea5361e..307494a 100644 --- a/kcidev/libs/common.py +++ b/kcidev/libs/common.py @@ -1,10 +1,20 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os + import toml def load_toml(settings): + if not settings: + if os.path.exists(".kci-dev.toml"): + settings = ".kci-dev.toml" + else: + homedir = os.path.expanduser("~") + settings = os.path.join(homedir, ".config", "kci-dev.toml") + if not os.path.exists(settings): + raise FileNotFoundError(f"Settings file {settings} not found") with open(settings) as fp: config = toml.load(fp) return config diff --git a/kcidev/main.py b/kcidev/main.py index c38e856..dd2d1fd 100755 --- a/kcidev/main.py +++ b/kcidev/main.py @@ -11,7 +11,7 @@ help="Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel changes on a enabled KernelCI server" ) @click.version_option("0.1.0", prog_name="kci-dev") -@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file") +@click.option("--settings", default=None, help="path of toml setting file") @click.option("--instance", help="API instance to use", required=False) @click.pass_context def cli(ctx, settings, instance):