@ethersphere/swarm-cli
Version:
CLI tool for Bee
195 lines (194 loc) • 7.1 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RootCommand = void 0;
const bee_js_1 = require("@ethersphere/bee-js");
const cafe_utility_1 = require("cafe-utility");
const furious_commander_1 = require("furious-commander");
const curl_1 = require("../../curl");
const utils_1 = require("../../utils");
const command_config_1 = require("./command-config");
const command_log_1 = require("./command-log");
class RootCommand {
constructor() {
Object.defineProperty(this, "beeApiUrl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "configFolder", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "configFile", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "verbosity", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "verbose", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "quiet", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "curl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "header", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "yes", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "dev", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "bee", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "console", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "appName", {
enumerable: true,
configurable: true,
writable: true,
value: 'swarm-cli'
});
Object.defineProperty(this, "commandConfig", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "sourcemap", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/**
* Resulting reference of the command for reflection (e.g. in tests)
*/
Object.defineProperty(this, "result", {
enumerable: true,
configurable: true,
writable: true,
value: cafe_utility_1.Optional.empty()
});
}
init() {
this.commandConfig = new command_config_1.CommandConfig(this.appName, this.console, this.configFile, this.configFolder);
this.sourcemap = furious_commander_1.Utils.getSourcemap();
command_config_1.CONFIG_OPTIONS.forEach((option) => {
this.maybeSetFromConfig(option);
});
const beeOptions = {};
if (this.curl) {
beeOptions.onRequest = curl_1.printCurlCommand;
}
if (this.header.length) {
beeOptions.headers = (0, utils_1.parseHeaders)(this.header);
}
this.bee = this.dev ? new bee_js_1.BeeDev(this.beeApiUrl, beeOptions) : new bee_js_1.Bee(this.beeApiUrl, beeOptions);
this.verbosity = command_log_1.VerbosityLevel.Normal;
if (this.quiet) {
this.verbosity = command_log_1.VerbosityLevel.Quiet;
}
else if (this.verbose) {
this.verbosity = command_log_1.VerbosityLevel.Verbose;
}
this.console = new command_log_1.CommandLog(this.verbosity);
}
maybeSetFromConfig(option) {
if (this.sourcemap[option.optionKey] === 'default') {
const value = this.commandConfig.config[option.propertyKey];
if (value !== undefined) {
this[option.propertyKey] = value;
}
}
}
}
__decorate([
(0, furious_commander_1.ExternalOption)('bee-api-url'),
__metadata("design:type", String)
], RootCommand.prototype, "beeApiUrl", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('config-folder'),
__metadata("design:type", String)
], RootCommand.prototype, "configFolder", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('config-file'),
__metadata("design:type", String)
], RootCommand.prototype, "configFile", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('verbosity'),
__metadata("design:type", Number)
], RootCommand.prototype, "verbosity", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('verbose'),
__metadata("design:type", Boolean)
], RootCommand.prototype, "verbose", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('quiet'),
__metadata("design:type", Boolean)
], RootCommand.prototype, "quiet", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('curl'),
__metadata("design:type", Boolean)
], RootCommand.prototype, "curl", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('header'),
__metadata("design:type", Array)
], RootCommand.prototype, "header", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('yes'),
__metadata("design:type", Boolean)
], RootCommand.prototype, "yes", void 0);
__decorate([
(0, furious_commander_1.ExternalOption)('dev'),
__metadata("design:type", Boolean)
], RootCommand.prototype, "dev", void 0);
exports.RootCommand = RootCommand;