update cli docs and fix cli scripts with new syntax
This commit is contained in:
89
qopconv.ce
89
qopconv.ce
@@ -9,19 +9,20 @@ function print_usage() {
|
||||
log.console(" <sources...> <archive> .. create archive from sources")
|
||||
}
|
||||
|
||||
function list(archive_path) {
|
||||
function list_archive(archive_path) {
|
||||
var blob = fd.slurp(archive_path)
|
||||
var archive = null
|
||||
if (!blob) {
|
||||
log.console("Could not open archive " + archive_path)
|
||||
return
|
||||
}
|
||||
var archive = null
|
||||
try {
|
||||
var _open = function() {
|
||||
archive = qop.open(blob)
|
||||
} catch(e) {
|
||||
log.console("Could not open archive " + archive_path + ": " + e.message)
|
||||
} disruption {
|
||||
log.console("Could not open archive " + archive_path)
|
||||
return
|
||||
}
|
||||
_open()
|
||||
|
||||
var files = archive.list()
|
||||
arrfor(files, function(f) {
|
||||
@@ -35,34 +36,41 @@ function list(archive_path) {
|
||||
|
||||
function unpack(archive_path) {
|
||||
var blob = fd.slurp(archive_path)
|
||||
var archive = null
|
||||
if (!blob) {
|
||||
log.console("Could not open archive " + archive_path)
|
||||
return
|
||||
}
|
||||
var archive = null
|
||||
try {
|
||||
var _open = function() {
|
||||
archive = qop.open(blob)
|
||||
} catch(e) {
|
||||
log.console("Could not open archive " + archive_path + ": " + e.message)
|
||||
} disruption {
|
||||
log.console("Could not open archive " + archive_path)
|
||||
return
|
||||
}
|
||||
_open()
|
||||
|
||||
var files = archive.list()
|
||||
arrfor(files, function(f) {
|
||||
var data = archive.read(f)
|
||||
var dir = null
|
||||
var parts = null
|
||||
var curr = null
|
||||
var fh = null
|
||||
var _mk = null
|
||||
if (data) {
|
||||
// Ensure directory exists
|
||||
var dir = fd.dirname(f)
|
||||
dir = fd.dirname(f)
|
||||
if (dir) {
|
||||
// recursive mkdir
|
||||
var parts = array(dir, '/')
|
||||
var curr = "."
|
||||
parts = array(dir, '/')
|
||||
curr = "."
|
||||
arrfor(parts, function(p) {
|
||||
curr += "/" + p
|
||||
try { fd.mkdir(curr) } catch(e) {}
|
||||
_mk = function() { fd.mkdir(curr) } disruption {}
|
||||
_mk()
|
||||
})
|
||||
}
|
||||
var fh = fd.open(f, "w")
|
||||
fh = fd.open(f, "w")
|
||||
fd.write(fh, data)
|
||||
fd.close(fh)
|
||||
log.console("Extracted " + f)
|
||||
@@ -73,9 +81,9 @@ function unpack(archive_path) {
|
||||
|
||||
function pack(sources, archive_path, read_dir) {
|
||||
var writer = qop.write(archive_path)
|
||||
|
||||
|
||||
var base_dir = read_dir || "."
|
||||
|
||||
|
||||
function add_recursive(path) {
|
||||
var full_path = base_dir + "/" + path
|
||||
if (path == ".") full_path = base_dir
|
||||
@@ -86,7 +94,7 @@ function pack(sources, archive_path, read_dir) {
|
||||
log.console("Could not stat " + full_path)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (st.isDirectory) {
|
||||
var list = fd.readdir(full_path)
|
||||
arrfor(list, function(item) {
|
||||
@@ -102,39 +110,44 @@ function pack(sources, archive_path, read_dir) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
arrfor(sources, function(s) {
|
||||
add_recursive(s)
|
||||
})
|
||||
|
||||
|
||||
writer.finalize()
|
||||
log.console("Created " + archive_path)
|
||||
}
|
||||
|
||||
if (!is_array(arg) || length(arg) < 1) {
|
||||
var sources = null
|
||||
var archive = null
|
||||
var read_dir = null
|
||||
var i = 0
|
||||
|
||||
if (!is_array(args) || length(args) < 1) {
|
||||
print_usage()
|
||||
} else {
|
||||
if (arg[0] == "-l") {
|
||||
if (length(arg) < 2) print_usage()
|
||||
else list(arg[1])
|
||||
} else if (arg[0] == "-u") {
|
||||
if (length(arg) < 2) print_usage()
|
||||
else unpack(arg[1])
|
||||
if (args[0] == "-l") {
|
||||
if (length(args) < 2) print_usage()
|
||||
else list_archive(args[1])
|
||||
} else if (args[0] == "-u") {
|
||||
if (length(args) < 2) print_usage()
|
||||
else unpack(args[1])
|
||||
} else {
|
||||
var sources = []
|
||||
var archive = null
|
||||
var read_dir = null
|
||||
var i = 0
|
||||
if (arg[0] == "-d") {
|
||||
read_dir = arg[1]
|
||||
sources = []
|
||||
archive = null
|
||||
read_dir = null
|
||||
i = 0
|
||||
if (args[0] == "-d") {
|
||||
read_dir = args[1]
|
||||
i = 2
|
||||
}
|
||||
|
||||
for (; i < length(arg) - 1; i++) {
|
||||
push(sources, arg[i])
|
||||
|
||||
for (; i < length(args) - 1; i++) {
|
||||
push(sources, args[i])
|
||||
}
|
||||
archive = arg[length(arg) - 1]
|
||||
|
||||
archive = args[length(args) - 1]
|
||||
|
||||
if (length(sources) == 0) {
|
||||
print_usage()
|
||||
} else {
|
||||
@@ -143,4 +156,4 @@ if (!is_array(arg) || length(arg) < 1) {
|
||||
}
|
||||
}
|
||||
|
||||
$stop()
|
||||
$stop()
|
||||
|
||||
Reference in New Issue
Block a user