|
1 | 1 | import typer |
2 | 2 |
|
| 3 | +from json import load |
| 4 | +from os import getenv, putenv, system |
| 5 | +from pprint import pprint |
| 6 | +from typing import Optional |
| 7 | + |
| 8 | +from .api import BuildtargetsApi |
| 9 | +from .api_client import ApiClient |
| 10 | +from .configuration import Configuration |
| 11 | +from .python_client.swagger_client.rest import ApiException |
| 12 | +from .utils import get_buildtargets, set_envvar_buildtarget |
| 13 | + |
3 | 14 |
|
4 | 15 | app = typer.Typer() |
5 | 16 |
|
| 17 | +buildtargets_app = typer.Typer() |
| 18 | + |
| 19 | +app.add_typer(buildtargets_app, name='buildtargets') |
| 20 | + |
6 | 21 |
|
7 | 22 | @app.callback() |
8 | 23 | def callback(): |
9 | 24 | """ |
10 | 25 | Python package for Unity Cloud Build api |
11 | 26 | """ |
| 27 | + |
| 28 | + |
| 29 | +@buildtargets_app.command() |
| 30 | +def set_var_json(json_dir: str, platform: Optional[str] = typer.Option('all', help='android, ios or all'), replace: bool = typer.Option(False, '--replace'), app_name: Optional[str] = typer.Option('', '--name')): |
| 31 | + with open(json_dir) as file: |
| 32 | + json = load(file) |
| 33 | + buildtargetslist = get_buildtargets(platform, app_name) |
| 34 | + set_envvar_buildtarget(buildtargetslist, json, replace) |
| 35 | + |
| 36 | + |
| 37 | +@buildtargets_app.command() |
| 38 | +def set_var(name: str, value: str, platform: Optional[str] = typer.Option('all', help='android, ios or all'), replace: bool = typer.Option(False, '--replace'), app_name: Optional[str] = typer.Option('', '--name')): |
| 39 | + buildtargetslist = get_buildtargets(platform, app_name) |
| 40 | + set_envvar_buildtarget(buildtargetslist, {name: value}, replace) |
| 41 | + |
| 42 | + |
| 43 | +@buildtargets_app.command() |
| 44 | +def get_list(platform: Optional[str] = typer.Option('all', help='android, ios or all'), name: Optional[str] = typer.Option('')): |
| 45 | + result = get_buildtargets(platform, name) |
| 46 | + typer.echo([item.buildtargetid for item in result]) |
| 47 | + |
| 48 | + |
| 49 | +@app.command() |
| 50 | +def show_env_vars(): |
| 51 | + typer.echo(f'UCB_API_KEY: {getenv("UCB_API_KEY")}') |
| 52 | + typer.echo(f'UCB_ORG_ID: {getenv("UCB_ORG_ID")}') |
| 53 | + typer.echo(f'UCB_PROJECT_ID: {getenv("UCB_PROJECT_ID")}') |
0 commit comments