From 7c74a74464df898bb0881b635802cf5d7ec4f89b Mon Sep 17 00:00:00 2001 From: Rafael Walter Date: Thu, 26 Nov 2020 20:20:59 -0300 Subject: [PATCH] output 7zip stdout to log --- src/action/extract.ts | 23 +++++++++++++------ src/action/levainShell.ts | 6 ++--- src/cmd/shell.ts | 9 ++++---- src/lib/{shellUtils.ts => os_shell.ts} | 0 .../repository/file_system_repository.test.ts | 2 +- src/lib/repository/file_system_repository.ts | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) rename src/lib/{shellUtils.ts => os_shell.ts} (100%) diff --git a/src/action/extract.ts b/src/action/extract.ts index 1cba44cc..52a902bd 100644 --- a/src/action/extract.ts +++ b/src/action/extract.ts @@ -5,6 +5,7 @@ import Action from "../lib/action.ts"; import Config from "../lib/config.ts"; import FileSystemPackage from '../lib/package/file_system_package.ts'; import {parseArgs} from "../lib/parseArgs.ts"; +import {OsShell} from '../lib/os_shell.ts'; // TODO: Use native TS/JS implementation instead of extra-bin files. export default class Extract implements Action { @@ -138,23 +139,31 @@ class SevenZip extends Extractor { async extractImpl(src: string, dst: string) { // TODO: Handle other os's - if (Deno.build.os != "windows") { + log.debug(`- 7z ${src} => ${dst}`); + if (!OsShell.isWindows()) { throw `${Deno.build.os} not supported`; } - log.debug(`- 7z ${src} => ${dst}`); - let args = `cmd /u /c path ${this.config.extraBinDir};%PATH% && ${this.config.extraBinDir}\\7z.exe x -bsp2 -o${dst} ${src}`.split(" "); log.debug(args) const p = Deno.run({ cmd: args, - stdout: "null" + stdout: "piped", + // stderr: "piped", }); - - let status = await p.status(); - if (!status.success) { + const rawOutput = await p.output(); + const status = await p.status(); + log.debug(`7z status ${JSON.stringify(status)}`) + + if (status.success) { + const output = new TextDecoder().decode(rawOutput) + log.debug(`7z output ${output}`) + } else { throw "CMD terminated with code " + status.code; + // const rawError = await p.stderrOutput() + // const errorString = new TextDecoder().decode(rawError) + // log.error(`7z errorString ${errorString}`) } } } diff --git a/src/action/levainShell.ts b/src/action/levainShell.ts index 683dcc07..492e119f 100644 --- a/src/action/levainShell.ts +++ b/src/action/levainShell.ts @@ -3,8 +3,8 @@ import * as log from "https://deno.land/std/log/mod.ts"; import Action from "../lib/action.ts"; import Config from "../lib/config.ts"; import FileSystemPackage from '../lib/package/file_system_package.ts'; -import { parseArgs } from "../lib/parseArgs.ts"; -import { OsShell } from '../lib/shellUtils.ts'; +import {parseArgs} from "../lib/parseArgs.ts"; +import {OsShell} from '../lib/os_shell.ts'; export default class LevainShell implements Action { constructor(private config: Config) { @@ -23,7 +23,7 @@ export default class LevainShell implements Action { ] }); - let osShell:OsShell = new OsShell(this.config, [ pkg.name ]); + let osShell: OsShell = new OsShell(this.config, [pkg.name]); osShell.saveVar = myArgs.saveVar; osShell.interactive = false; osShell.stripCRLF = myArgs.stripCRLF; diff --git a/src/cmd/shell.ts b/src/cmd/shell.ts index ba19cef0..65809c2f 100644 --- a/src/cmd/shell.ts +++ b/src/cmd/shell.ts @@ -2,8 +2,7 @@ import * as log from "https://deno.land/std/log/mod.ts"; import Command from "./command.ts"; import Config from "../lib/config.ts"; -import FileSystemPackage from "../lib/package/file_system_package.ts"; -import { OsShell } from '../lib/shellUtils.ts'; +import {OsShell} from '../lib/os_shell.ts'; export default class Shell implements Command { constructor(private config: Config) { @@ -14,15 +13,15 @@ export default class Shell implements Command { log.info("=================================="); log.info(`shell ${JSON.stringify(args)}`); - let pkgNames:string[] = []; + let pkgNames: string[] = []; if (args && args.length > 0) { pkgNames = args; } else { - pkgNames = [ this.config.defaultPackage ]; + pkgNames = [this.config.defaultPackage]; } - let osShell:OsShell = new OsShell(this.config, pkgNames, true); + let osShell: OsShell = new OsShell(this.config, pkgNames, true); osShell.interactive = true; await osShell.execute([]); diff --git a/src/lib/shellUtils.ts b/src/lib/os_shell.ts similarity index 100% rename from src/lib/shellUtils.ts rename to src/lib/os_shell.ts diff --git a/src/lib/repository/file_system_repository.test.ts b/src/lib/repository/file_system_repository.test.ts index fad0303c..9096ca5d 100644 --- a/src/lib/repository/file_system_repository.test.ts +++ b/src/lib/repository/file_system_repository.test.ts @@ -2,7 +2,7 @@ import {assert, assertEquals} from "https://deno.land/std/testing/asserts.ts"; import Config from "../config.ts"; import FileSystemRepository from "./file_system_repository.ts"; import FileSystemPackage from "../package/file_system_package.ts"; -import {OsShell} from '../shellUtils.ts'; +import {OsShell} from '../os_shell.ts'; import {assertArrayIncludesElements} from '../assert_utils.ts'; Deno.test('should have a name', () => { diff --git a/src/lib/repository/file_system_repository.ts b/src/lib/repository/file_system_repository.ts index 84c6285d..3db7158a 100644 --- a/src/lib/repository/file_system_repository.ts +++ b/src/lib/repository/file_system_repository.ts @@ -7,7 +7,7 @@ import Repository from './repository.ts' import FileSystemPackage from '../package/file_system_package.ts' import Config from '../config.ts'; import {Timer} from "../timer.ts"; -import {OsShell} from '../shellUtils.ts'; +import {OsShell} from '../os_shell.ts'; export default class FileSystemRepository implements Repository { readonly excludeDirs = ['$RECYCLE.BIN', 'node_modules', '.git']