Skip to content

Commit

Permalink
output 7zip stdout to log
Browse files Browse the repository at this point in the history
  • Loading branch information
rafawalter committed Nov 26, 2020
1 parent 8b2f7fd commit 7c74a74
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
23 changes: 16 additions & 7 deletions src/action/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/action/levainShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/cmd/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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([]);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/repository/file_system_repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/repository/file_system_repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 7c74a74

Please sign in to comment.