From c5005cadceee5245f95965a62d65d093a1c3a5ed Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Thu, 22 Aug 2024 16:40:46 -0300 Subject: [PATCH 1/3] feat(cli): add `--command` to `sunodo shell` --- .changeset/twenty-walls-share.md | 5 +++++ apps/cli/src/commands/shell.ts | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 .changeset/twenty-walls-share.md diff --git a/.changeset/twenty-walls-share.md b/.changeset/twenty-walls-share.md new file mode 100644 index 00000000..4acf6962 --- /dev/null +++ b/.changeset/twenty-walls-share.md @@ -0,0 +1,5 @@ +--- +"@cartesi/cli": patch +--- + +add `--command` to `sunodo shell` to allow defining a different shell, defaulting to `/bin/bash` diff --git a/apps/cli/src/commands/shell.ts b/apps/cli/src/commands/shell.ts index 3c8a928b..00256cee 100644 --- a/apps/cli/src/commands/shell.ts +++ b/apps/cli/src/commands/shell.ts @@ -22,12 +22,15 @@ export default class Shell extends BaseCommand { description: "run as root user", default: false, }), + command: Flags.string({ + description: "shell command to use (eg.: /bin/zsh)", + required: false, + default: "/bin/bash", + }), }; - private async startShell( - ext2Path: string, - runAsRoot: boolean, - ): Promise { + private async startShell(ext2Path: string): Promise { + const { flags } = await this.parse(Shell); const containerDir = "/mnt"; const bind = `${path.resolve(path.dirname(ext2Path))}:${containerDir}`; const ext2 = path.join(containerDir, path.basename(ext2Path)); @@ -47,7 +50,7 @@ export default class Shell extends BaseCommand { `--flash-drive=label:${driveLabel},filename:${ext2}`, ]; - if (runAsRoot) { + if (flags["run-as-root"]) { args.push("--append-init=USER=root"); } @@ -57,14 +60,12 @@ export default class Shell extends BaseCommand { args.push("-it"); } - await execa("docker", [...args, "--", "/bin/bash"], { + await execa("docker", [...args, "--", flags.command], { stdio: "inherit", }); } public async run(): Promise { - const { flags } = await this.parse(Shell); - // use pre-existing image or build dapp image const ext2Path = this.getContextPath("image.ext2"); if (!fs.existsSync(ext2Path)) { @@ -74,6 +75,6 @@ export default class Shell extends BaseCommand { } // execute the machine and save snapshot - await this.startShell(ext2Path, flags["run-as-root"]); + await this.startShell(ext2Path); } } From 2446a2d5043598af54c040907a527167cde542c0 Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Thu, 22 Aug 2024 18:04:28 -0300 Subject: [PATCH 2/3] fixup! feat(cli): add `--command` to `sunodo shell` --- apps/cli/src/commands/shell.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/cli/src/commands/shell.ts b/apps/cli/src/commands/shell.ts index 00256cee..bc59b997 100644 --- a/apps/cli/src/commands/shell.ts +++ b/apps/cli/src/commands/shell.ts @@ -23,9 +23,9 @@ export default class Shell extends BaseCommand { default: false, }), command: Flags.string({ - description: "shell command to use (eg.: /bin/zsh)", + description: "shell command to use (eg.: /bin/bash)", required: false, - default: "/bin/bash", + default: "/bin/sh", }), }; From 0153d86b0c10df3103276bbaaa236b1b9b03fb51 Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Mon, 23 Sep 2024 16:00:06 -0300 Subject: [PATCH 3/3] fixup! feat(cli): add `--command` to `sunodo shell` --- apps/cli/src/commands/shell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/cli/src/commands/shell.ts b/apps/cli/src/commands/shell.ts index bc59b997..8a5a0b77 100644 --- a/apps/cli/src/commands/shell.ts +++ b/apps/cli/src/commands/shell.ts @@ -25,7 +25,7 @@ export default class Shell extends BaseCommand { command: Flags.string({ description: "shell command to use (eg.: /bin/bash)", required: false, - default: "/bin/sh", + default: "/bin/bash", }), };