Skip to content

Commit

Permalink
Merge pull request #10 from nuclearcat/add-instance-option
Browse files Browse the repository at this point in the history
feat(instance): Add --instance option to arguments and config
  • Loading branch information
aliceinwire authored Sep 12, 2024
2 parents 17522ac + 8e6789e commit fbf72dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 11 additions & 1 deletion .kci-dev.toml.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[connection]
default_instance="local"

[local]
host="https://127.0.0.1"
token="example"

[staging]
host="https://staging.kernelci.org:9100/"
token="example"

[production]
host="https://kernelci-pipeline.westus3.cloudapp.azure.com/"
token="example"
13 changes: 12 additions & 1 deletion kci-dev/kci-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
)
@click.version_option("0.0.1", prog_name="kci-dev")
@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file")
@click.option("--instance", help="API instance to use", required=False)
@click.pass_context
def cli(ctx, settings):
def cli(ctx, settings, instance):
ctx.obj = {"CFG": load_toml(settings)}
if instance:
ctx.obj["INSTANCE"] = instance
else:
ctx.obj["INSTANCE"] = ctx.obj["CFG"].get("default_instance")
if not ctx.obj["INSTANCE"]:
click.secho("No instance defined in settings or as argument", fg="red")
raise click.Abort()
if ctx.obj["INSTANCE"] not in ctx.obj["CFG"]:
click.secho(f"Instance {ctx.obj['INSTANCE']} not found in {settings}", fg="red")
raise click.Abort()
pass


Expand Down
5 changes: 3 additions & 2 deletions kci-dev/subcommands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def send_build(url, patch, branch, treeurl, token):
@click.pass_context
def commit(ctx, repository, branch, private, path):
config = ctx.obj.get("CFG")
url = api_connection(config["connection"]["host"])
instance = ctx.obj.get("INSTANCE")
url = api_connection(config[instance]["host"])
diff = find_diff(path, branch, repository)
send_build(url, diff, branch, repository, config["connection"]["token"])
send_build(url, diff, branch, repository, config[instance]["token"])


if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions kci-dev/subcommands/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def send_build(url, patch, branch, treeurl, token):
@click.pass_context
def patch(ctx, repository, branch, private, patch):
config = ctx.obj.get("CFG")
url = api_connection(config["connection"]["host"])
instance = ctx.obj.get("INSTANCE")
url = api_connection(config[instance]["host"])
patch = open(patch, "rb")
send_build(url, patch, branch, repository, config["connection"]["token"])
send_build(url, patch, branch, repository, config[instance]["token"])


if __name__ == "__main__":
Expand Down

0 comments on commit fbf72dc

Please sign in to comment.