diff --git a/bin/esiur.cjs b/bin/esiur.cjs index 97cfe7f..458bd67 100644 --- a/bin/esiur.cjs +++ b/bin/esiur.cjs @@ -1,13 +1,61 @@ #!/usr/bin/env node -console.log("Esiur Shell"); -console.log("\t use: 'await wh.get(url, );' to get a resource."); -const { spawn } = require("child_process"); -const { pathToFileURL } = require("url"); -let url = pathToFileURL(__dirname).href + '/../src/esiur.js'; +if (process.argv.length == 2) { + console.log("Usage: [arguments]"); + console.log(""); + console.log("Available commands:"); + console.log("\tget-template\tGet a template from an IIP link."); + console.log("\tshell\tStart Node.js REPL with Esiur module loaded."); + console.log("\tversion: Print Esiur version."); + console.log(""); + console.log("Global options:"); + console.log("\t-u, --username\tAuthentication username"); + console.log("\t-p, --password\tAuthentication password"); + console.log("\t-d, --dir\tName of the directory to generate model inside."); + process.exit(); +} -spawn('node', ["-i", "-e", `import('${url}');`], { - stdio: 'inherit' -}); \ No newline at end of file + +const cmd = process.argv[2].toLowerCase(); +const args = process.argv.slice(3); + +if (cmd == "shell") { + + console.log("Esiur Shell"); + console.log("\t use: 'await wh.get(url, );' to get a resource."); + + const { spawn } = require("child_process"); + const { pathToFileURL } = require("url"); + + let url = pathToFileURL(__dirname).href + '/../src/esiur.js'; + + spawn('node', ["-i", "-e", `import('${url}');`], { + stdio: 'inherit' + }); +} +else if (cmd == "get-template") +{ + // get username + let username = getOption(args, "--username", "-u"); + let password = getOption(args, "--password", "-p"); + let dir = getOption(args, "--dir", "-d"); + + if (args.length == 0){ + console.error("No URL specified."); + process.exit(); + } + + let url = args[0]; + + console.log(`Getting ${url} ${username} ${password} ${dir}`); +} + +function getOption(args, option, abbreviation) { + let index = args.indexOf(abbreviation); + if (index == -1) index = args.indexOf(option); + if (index > -1 && index + 1 < args.length) + return args.slice(index, index + 1)[1]; + return null; +} \ No newline at end of file diff --git a/src/Net/IIP/DistributedConnection.js b/src/Net/IIP/DistributedConnection.js index 394bf25..a9025eb 100644 --- a/src/Net/IIP/DistributedConnection.js +++ b/src/Net/IIP/DistributedConnection.js @@ -892,13 +892,17 @@ export default class DistributedConnection extends IStore { if (dataType.identifier == TransmissionTypeIdentifier.ResourceList || dataType.identifier == TransmissionTypeIdentifier.List) { + // remove from suspended. + this._suspendedResources.remove(r._p.instanceId); + // parse them as int var id = data.getUint32(8); + + // id changed ? if (id != r._p.instanceId) r._p.instanceId = id; this._neededResources.set(id, r); - this._suspendedResources.remove(id); await this.fetch(id, null);