bilderhic
Advanced tools
Comparing version 1.0.78 to 1.1.0
{ | ||
"name": "bilderhic", | ||
"version": " 1.0.78", | ||
"version": " 1.1.0", | ||
"description": "Bilderhic (bhic) is a smart and simple command tool for automatization.", | ||
@@ -78,2 +78,2 @@ "preferGlobal": true, | ||
} | ||
} | ||
} |
@@ -40,2 +40,7 @@ <img src="https://lucianorasente.com/public_img/bhic.png" style="max-width:100px;width:100%;"> | ||
> Set variable value (if the variable doesn't exists) | ||
```bash | ||
env set-default <key> <value> | ||
``` | ||
> Set variable from user input | ||
@@ -42,0 +47,0 @@ ```bash |
@@ -12,2 +12,3 @@ const fs = require("fs"); | ||
} | ||
if (args[0] === "load") { | ||
@@ -20,2 +21,3 @@ const filename = this.parsePath(args[1]); | ||
} | ||
if (args[0] === "debug") { | ||
@@ -39,2 +41,3 @@ if (args.length === 1) { | ||
} | ||
if (args[0] === "set") { | ||
@@ -49,2 +52,11 @@ const key = args[1]; | ||
} | ||
if (args[0] === "set-default") { | ||
const key = args[1]; | ||
const value = this.environment.applyVariables(args[2]); | ||
this.environment.setDefaultVariable(key, value); | ||
this.debug(this.environment.variables); | ||
return this.codes.success; | ||
} | ||
if (args[0] === "prompt") { | ||
@@ -83,2 +95,3 @@ const key = args[1]; | ||
} | ||
if (args[0] === "add") { | ||
@@ -85,0 +98,0 @@ let parent = 0; |
@@ -99,2 +99,13 @@ const path = require("path"); | ||
setDefaultVariable(id, value) { | ||
const existing = this.getVariable(id); | ||
if (typeof existing === "undefined") { | ||
this.variables[id] = value; | ||
} | ||
} | ||
getVariable(id) { | ||
return this.getVariables()[id]; | ||
} | ||
getVariables() { | ||
@@ -101,0 +112,0 @@ const variables = {}; |
@@ -8,2 +8,96 @@ const { expect } = require("chai"); | ||
describe("Environment", () => { | ||
describe("setDefaultVariable", () => { | ||
beforeEach(() => { | ||
env = new Environment(__dirname); | ||
env.setVariables({ | ||
name: "Test", | ||
version: { | ||
minor: 0, | ||
mayor: 1, | ||
patch: 5, | ||
subversion: { | ||
number: 3, | ||
}, | ||
}, | ||
}); | ||
}); | ||
it("set simple non-existing default variable", () => { | ||
env.setDefaultVariable("lastName", "Good"); | ||
const result = env.getVariable("lastName"); | ||
const expected = "Good"; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("set simple existing default variable", () => { | ||
env.setDefaultVariable("name", "Fail"); | ||
const result = env.getVariable("name"); | ||
const expected = "Test"; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("set chained existing variables", () => { | ||
env.setDefaultVariable("version.minor", 999); | ||
const result = env.getVariable("version.minor"); | ||
const expected = 0; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("set chained non-existing variables", () => { | ||
env.setDefaultVariable("version.xyz", 999); | ||
const result = env.getVariable("version.xyz"); | ||
const expected = 999; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("set chained (2 lvl) existing variables", () => { | ||
env.setDefaultVariable("version.subversion.number", 123); | ||
const result = env.getVariable("version.subversion.number"); | ||
const expected = 3; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("set chained (2 lvl) non-existing variables", () => { | ||
env.setDefaultVariable("version.subversion.xyz", 123); | ||
const result = env.getVariable("version.subversion.xyz"); | ||
const expected = 123; | ||
expect(result).to.equals(expected); | ||
}); | ||
}); | ||
describe("getVariable", () => { | ||
beforeEach(() => { | ||
env = new Environment(__dirname); | ||
env.setVariables({ | ||
name: "Test", | ||
version: { | ||
minor: 0, | ||
mayor: 1, | ||
patch: 5, | ||
subversion: { | ||
number: 3, | ||
}, | ||
}, | ||
}); | ||
}); | ||
it("get simple variable", () => { | ||
const result = env.getVariable("name"); | ||
const expected = "Test"; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("get chained variables", () => { | ||
const result = env.getVariable("version.minor"); | ||
const expected = 0; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("get chained (2 lvl) variables", () => { | ||
const result = env.getVariable("version.subversion.number"); | ||
const expected = 3; | ||
expect(result).to.equals(expected); | ||
}); | ||
}); | ||
describe("applyVariables", () => { | ||
@@ -10,0 +104,0 @@ beforeEach(() => { |
130692
3371
380