Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/lsa
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('../lib/ls-archive-cli')()
require('../src/ls-archive-cli')()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"bugs": {
"url": "https://github.com/pulsar-edit/node-ls-archive/issues"
},
"main": "./lib/ls-archive.js",
"main": "./src/ls-archive.js",
"bin": {
"lsa": "./bin/lsa"
},
Expand Down
8 changes: 4 additions & 4 deletions spec/bzip-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archive = require '../lib/ls-archive'
archive = require '../src/ls-archive'
path = require 'path'

describe "bzipped tar files", ->
Expand Down Expand Up @@ -32,7 +32,7 @@ describe "bzipped tar files", ->
expect(bzipPaths[0].isDirectory()).toBe false
expect(bzipPaths[0].isFile()).toBe true
expect(bzipPaths[0].isSymbolicLink()).toBe false

it "returns files in the bzipped tar archive", ->
bzipPaths = null
callback = (error, paths) -> bzipPaths = paths
Expand Down Expand Up @@ -68,7 +68,7 @@ describe "bzipped tar files", ->
expect(bzipPaths[0].isDirectory()).toBe true
expect(bzipPaths[0].isFile()).toBe false
expect(bzipPaths[0].isSymbolicLink()).toBe false

it "returns folders in the bzipped tar archive", ->
bzipPaths = null
callback = (error, paths) -> bzipPaths = paths
Expand Down Expand Up @@ -125,7 +125,7 @@ describe "bzipped tar files", ->
archive.readFile(archivePath, 'file.txt', callback)
waitsFor -> pathContents?
runs -> expect(pathContents.toString()).toBe 'hello\n'

it "calls back with the contents of the given path", ->
archivePath = path.join(fixturesRoot, 'one-file.tbz2')
pathContents = null
Expand Down
2 changes: 1 addition & 1 deletion spec/common-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archive = require '../lib/ls-archive'
archive = require '../src/ls-archive'
path = require 'path'

describe "Common behavior", ->
Expand Down
2 changes: 1 addition & 1 deletion spec/gzip-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archive = require '../lib/ls-archive'
archive = require '../src/ls-archive'
path = require 'path'

describe "gzipped tar files", ->
Expand Down
2 changes: 1 addition & 1 deletion spec/tar-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archive = require '../lib/ls-archive'
archive = require '../src/ls-archive'
path = require 'path'

describe "tar files", ->
Expand Down
2 changes: 1 addition & 1 deletion spec/zip-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archive = require '../lib/ls-archive'
archive = require '../src/ls-archive'
path = require 'path'

describe "zip files", ->
Expand Down
45 changes: 0 additions & 45 deletions src/ls-archive-cli.coffee

This file was deleted.

60 changes: 60 additions & 0 deletions src/ls-archive-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const path = require("path");
const async = require("async");
const colors = require("colors");
const optimist = require("optimist");
const archive = require("./ls-archive.js");

module.exports = function() {
const cli = optimist.usage(`Usage: lsa [file ...]

List the files and folders inside an archive file.

Supports .zip, .tar, .tar.gz, .tgz, .tar.bz2, .tbz and .tbz2 files.`)
.describe('colors', 'Enable colored output')
.default('colors', true)
.boolean('colors')
.describe('help', 'Show this message')
.alias('h', 'help')
.demand(1);

if (cli.argv.help) {
cli.showHelp();
return;
}
if (!cli.argv.colors) {
colors.setTheme({
cyan: 'stripColors',
red: 'stripColors'
});
}
let queue = async.queue(function(archivePath, callback) {
return (function(archivePath) {
return archive.list(archivePath, function(error, files) {
if (error != null) {
console.error(`Error reading: ${archivePath}`.red);
} else {

console.log(`${archivePath.cyan} (${files.length})`);
for (let i = 0; i < files.length; i++) {
let file = files[i];
let prefix;
if (i === files.length - 1) {
prefix = '\u2514\u2500\u2500 ';
} else {
prefix = '\u251C\u2500\u2500 ';
}
console.log(`${prefix}${file.getPath()}`);
}

console.log();
}
return callback();
});
})(archivePath);
});

let files = cli.argv._;
return files.forEach(function(file) {
return queue.push(path.resolve(process.cwd(), file));
});
};
Loading