From 90f1a1d39c37e3d63fba4dde0b6575b546c2201b Mon Sep 17 00:00:00 2001 From: luckasRanarison Date: Mon, 11 Nov 2024 11:57:48 +0300 Subject: [PATCH 1/3] fix(cli): implement `--prefix` argument --- src/meta-cli/src/cli/gen.rs | 1 + src/meta-cli/src/cli/list.rs | 1 + src/meta-cli/src/cli/serialize.rs | 1 + src/meta-cli/src/deploy/actors/task/action.rs | 1 + src/meta-cli/src/deploy/actors/task/command.rs | 4 ++++ src/meta-cli/src/deploy/actors/task/deploy.rs | 3 ++- src/meta-cli/src/deploy/actors/task/list.rs | 2 ++ src/meta-cli/src/deploy/actors/task/serialize.rs | 2 ++ src/typegraph/deno/src/envs/cli.ts | 2 +- 9 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/meta-cli/src/cli/gen.rs b/src/meta-cli/src/cli/gen.rs index 9d3c7236a2..cdf4fcd97c 100644 --- a/src/meta-cli/src/cli/gen.rs +++ b/src/meta-cli/src/cli/gen.rs @@ -185,6 +185,7 @@ async fn load_tg_at( let init = TaskManagerInit::::new( config.clone(), SerializeActionGenerator::new( + None, config_dir.clone(), dir.into(), config diff --git a/src/meta-cli/src/cli/list.rs b/src/meta-cli/src/cli/list.rs index c13128b583..60e4e29fb3 100644 --- a/src/meta-cli/src/cli/list.rs +++ b/src/meta-cli/src/cli/list.rs @@ -50,6 +50,7 @@ impl Action for List { let console = ConsoleActor::new(Arc::clone(&config)).start(); let action_generator = ListActionGenerator::new( + node.prefix.clone(), config.dir().unwrap_or_log().into(), dir.clone().into(), config diff --git a/src/meta-cli/src/cli/serialize.rs b/src/meta-cli/src/cli/serialize.rs index 37b6dc7469..c525354fea 100644 --- a/src/meta-cli/src/cli/serialize.rs +++ b/src/meta-cli/src/cli/serialize.rs @@ -65,6 +65,7 @@ impl Action for Serialize { let console = ConsoleActor::new(Arc::clone(&config)).start(); let action_generator = SerializeActionGenerator::new( + self.prefix.clone(), config.dir().unwrap_or_log().into(), dir.into(), config diff --git a/src/meta-cli/src/deploy/actors/task/action.rs b/src/meta-cli/src/deploy/actors/task/action.rs index 58cf134414..1f8ddf42aa 100644 --- a/src/meta-cli/src/deploy/actors/task/action.rs +++ b/src/meta-cli/src/deploy/actors/task/action.rs @@ -12,6 +12,7 @@ use tokio::process::Command; #[derive(Debug, Clone)] pub struct SharedActionConfig { pub command: &'static str, + pub prefix: Option, pub config_dir: Arc, pub working_dir: Arc, pub migrations_dir: Arc, diff --git a/src/meta-cli/src/deploy/actors/task/command.rs b/src/meta-cli/src/deploy/actors/task/command.rs index 6aabfe64dd..01b8ca8040 100644 --- a/src/meta-cli/src/deploy/actors/task/command.rs +++ b/src/meta-cli/src/deploy/actors/task/command.rs @@ -102,6 +102,10 @@ impl CommandContext { command .current_dir(shared_config.working_dir.to_str().unwrap()) + .env( + "MCLI_PREFIX", + shared_config.prefix.clone().unwrap_or_default(), + ) .env("MCLI_VERSION", crate::build::PKG_VERSION) .env("MCLI_TYPEGRAPH_PATH", path.display().to_string()) .env("MCLI_COMMAND", shared_config.command) diff --git a/src/meta-cli/src/deploy/actors/task/deploy.rs b/src/meta-cli/src/deploy/actors/task/deploy.rs index f526d775b4..5c20c15e5a 100644 --- a/src/meta-cli/src/deploy/actors/task/deploy.rs +++ b/src/meta-cli/src/deploy/actors/task/deploy.rs @@ -61,10 +61,10 @@ impl DeployActionGenerator { destructive_migrations: bool, // TODO enum { Fail, Reset, Ask } ) -> Self { Self { - node, secrets, shared_config: SharedActionConfig { command: "deploy", + prefix: node.prefix.clone(), config_dir, working_dir, migrations_dir, @@ -76,6 +76,7 @@ impl DeployActionGenerator { artifact_resolution: true, } .into(), + node, } } } diff --git a/src/meta-cli/src/deploy/actors/task/list.rs b/src/meta-cli/src/deploy/actors/task/list.rs index f2e6b26ec5..b880a91fef 100644 --- a/src/meta-cli/src/deploy/actors/task/list.rs +++ b/src/meta-cli/src/deploy/actors/task/list.rs @@ -31,6 +31,7 @@ pub struct ListActionGenerator { impl ListActionGenerator { pub fn new( + prefix: Option, config_dir: Arc, working_dir: Arc, migrations_dir: Arc, @@ -39,6 +40,7 @@ impl ListActionGenerator { Self { shared_config: SharedActionConfig { command: "list", + prefix, config_dir, working_dir, migrations_dir, diff --git a/src/meta-cli/src/deploy/actors/task/serialize.rs b/src/meta-cli/src/deploy/actors/task/serialize.rs index fefa118033..0a01ea8cfd 100644 --- a/src/meta-cli/src/deploy/actors/task/serialize.rs +++ b/src/meta-cli/src/deploy/actors/task/serialize.rs @@ -32,6 +32,7 @@ pub struct SerializeActionGenerator { impl SerializeActionGenerator { pub fn new( + prefix: Option, config_dir: Arc, working_dir: Arc, migrations_dir: Arc, @@ -40,6 +41,7 @@ impl SerializeActionGenerator { Self { shared_config: SharedActionConfig { command: "serialize", + prefix, config_dir, working_dir, migrations_dir, diff --git a/src/typegraph/deno/src/envs/cli.ts b/src/typegraph/deno/src/envs/cli.ts index 62e0295150..e15a5dcb35 100644 --- a/src/typegraph/deno/src/envs/cli.ts +++ b/src/typegraph/deno/src/envs/cli.ts @@ -78,7 +78,7 @@ export function loadCliEnv(): CliEnv | null { for (const key of optionalCliEnvs) { const name = `MCLI_${key.toLocaleUpperCase()}`; const envValue = env[name]; - if (envValue != null) { + if (envValue) { record[key] = envValue; } } From 99fcf4f43c3515cf966039d43be842a0f44e22b7 Mon Sep 17 00:00:00 2001 From: luckasRanarison Date: Mon, 11 Nov 2024 12:52:31 +0300 Subject: [PATCH 2/3] fix: missing python update --- src/typegraph/python/typegraph/envs/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/typegraph/python/typegraph/envs/cli.py b/src/typegraph/python/typegraph/envs/cli.py index 9471001d4f..5de2693db9 100644 --- a/src/typegraph/python/typegraph/envs/cli.py +++ b/src/typegraph/python/typegraph/envs/cli.py @@ -60,8 +60,7 @@ def load(cls) -> Optional["CliEnv"]: for key in _optional_cli_envs: env_name = "MCLI_" + key.upper() - d[key] = environ.get(env_name) - + d[key] = environ.get(env_name) or None try: d["command"] = Command(d["command"]) except ValueError as e: From 1be4bbffbbc6c0370084162a2a1845c82caf57d1 Mon Sep 17 00:00:00 2001 From: luckasRanarison Date: Tue, 12 Nov 2024 19:30:08 +0300 Subject: [PATCH 3/3] fix: better optionals --- src/meta-cli/src/deploy/actors/task/command.rs | 11 +++++++---- src/typegraph/python/typegraph/envs/cli.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/meta-cli/src/deploy/actors/task/command.rs b/src/meta-cli/src/deploy/actors/task/command.rs index 01b8ca8040..22d5878d18 100644 --- a/src/meta-cli/src/deploy/actors/task/command.rs +++ b/src/meta-cli/src/deploy/actors/task/command.rs @@ -100,12 +100,10 @@ impl CommandContext { path, } = self; + let optional_envs = [("MCLI_PREFIX", shared_config.prefix.clone())]; + command .current_dir(shared_config.working_dir.to_str().unwrap()) - .env( - "MCLI_PREFIX", - shared_config.prefix.clone().unwrap_or_default(), - ) .env("MCLI_VERSION", crate::build::PKG_VERSION) .env("MCLI_TYPEGRAPH_PATH", path.display().to_string()) .env("MCLI_COMMAND", shared_config.command) @@ -126,6 +124,11 @@ impl CommandContext { "MCLI_ARTIFACT_RESOLUTION", shared_config.artifact_resolution.to_string(), ) + .envs( + optional_envs + .into_iter() + .filter_map(|(k, v)| v.map(|v| (k, v))), + ) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()); diff --git a/src/typegraph/python/typegraph/envs/cli.py b/src/typegraph/python/typegraph/envs/cli.py index 5de2693db9..422a54f123 100644 --- a/src/typegraph/python/typegraph/envs/cli.py +++ b/src/typegraph/python/typegraph/envs/cli.py @@ -60,7 +60,7 @@ def load(cls) -> Optional["CliEnv"]: for key in _optional_cli_envs: env_name = "MCLI_" + key.upper() - d[key] = environ.get(env_name) or None + d[key] = environ.get(env_name) try: d["command"] = Command(d["command"]) except ValueError as e: