Skip to content

Commit

Permalink
Merge pull request #3 from m0rphtail/dev
Browse files Browse the repository at this point in the history
version one
  • Loading branch information
m0rphtail authored May 5, 2021
2 parents c91f1a9 + 869eceb commit 79a47f6
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 44 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

### <em>cli tool to get system info</em>

- [Screenshots](#screenshots)
- [Install](#install)
- [Usage](#usage)

---

## Screenshots
Expand Down
4 changes: 2 additions & 2 deletions bin/arch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require("os");

module.exports = function () {
console.log(`Arch : ${os.arch()}`);
module.exports = () => {
return `${os.arch()}`;
};
13 changes: 3 additions & 10 deletions bin/cpu.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const os = require("os");
const chalk = require("chalk");

module.exports = function () {
module.exports = () => {
const cpu = os.cpus();
const fullName = cpu[0].model;
const speed = "@" + String(cpu[0].speed);
//const speed = "@" + String(cpu[0].speed);

for (var i = 0; i < fullName.length; i++) {
var maker = fullName.substr(0, fullName.indexOf(" "));
Expand All @@ -14,11 +13,5 @@ module.exports = function () {
var model = fullName.substr(maker.length + 1, fullName.length);
}

if (maker == "AMD") {
console.log("CPU :", chalk.red(maker), model, speed, "MHz");
} else if (maker == "INTEL") {
console.log("CPU :", chalk.blue(maker), model, speed, "MHz");
} else {
console.log("CPU :", maker, model, speed, "MHz");
}
return `${maker} ${model}`;
};
4 changes: 2 additions & 2 deletions bin/hostname.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require("os");

module.exports = function () {
console.log(`Hostname : ${os.hostname()}`);
module.exports = () => {
return `${os.hostname()}`;
};
4 changes: 2 additions & 2 deletions bin/kernel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require("os");

module.exports = function () {
console.log(`Kernel : ${os.release()}`);
module.exports = () => {
return `${os.release()}`;
};
16 changes: 8 additions & 8 deletions bin/memory.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const os = require("os");

module.exports = function () {
module.exports = () => {
const totalMemory = os.totalmem();
const freeMemory = os.freemem();
console.log(
"RAM :",
String(Math.round((totalMemory - freeMemory) / (1024 * 1024))),
"MiB /",
String(Math.round(totalMemory / (1024 * 1024))),
"MiB"
);
const usage =
String(
Math.round(totalMemory / (1024 * 1024) - freeMemory / (1024 * 1024)) +
" MiB / " +
Math.round(totalMemory / (1024 * 1024))
) + " MiB";
return `${usage}`;
};
51 changes: 37 additions & 14 deletions bin/system-z.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const hostname = require("./hostname");
const type = require("./type");
const kernel = require("./kernel");
const uptime = require("./uptime");
const boxen = require("boxen");

const tool = new Command();

Expand All @@ -25,20 +26,42 @@ tool

tool.parse(process.argv);

display = (title, func) => {
line = title + " : " + func;
console.log(boxen(line, { padding: 1, borderStyle: "round" }));
};

displayAll = () => {
const H = "Hostname : " + hostname();
const o = "OS : " + type();
const k = "Kernel : " + kernel();
const a = "Arch : " + arch();
const c = "CPU : " + cpu();
const m = "RAM : " + memory();
const u = "Uptime : " + uptime();

console.log(
boxen(`${H}\n${o}\n${k}\n${a}\n${c}\n${m}\n${u}`, {
padding: 1,
borderStyle: "round",
})
);
};

const options = tool.opts();
if (options.arch) arch();
else if (options.cpu) cpu();
else if (options.memory) memory();
else if (options.hostname) hostname();
else if (options.type) type();
else if (options.kernel) kernel();
else if (options.uptime) uptime();
if (options.arch) display("Arch", arch());
else if (options.cpu) display("CPU", cpu());
else if (options.memory) display("RAM", memory());
else if (options.hostname) display("Hostname", hostname());
else if (options.os) display("OS", type());
else if (options.kernel) display("Kernel", kernel());
else if (options.uptime) display("Uptime", uptime());
else {
hostname();
type();
kernel();
arch();
cpu();
memory();
uptime();
// console.log(
// boxen(
// `${hostname()}\n${type()}\n${kernel()}\n${arch()}\n${cpu()}\n${memory()}\n${uptime()}`,
// { padding: 1, borderStyle: "round" }
// )
//);
displayAll();
}
4 changes: 2 additions & 2 deletions bin/type.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require("os");

module.exports = function () {
console.log(`OS : ${os.type()}`);
module.exports = () => {
return `${os.type()}`;
};
7 changes: 4 additions & 3 deletions bin/uptime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const os = require("os");

module.exports = function () {
//TODO do better math
console.log("Uptime :", String(Math.floor((os.uptime()/60))) ,"mins");
module.exports = () => {
//TODO do better math
const uptime = String(Math.floor(os.uptime() / 60));
return `${uptime} mins`;
};
Binary file modified docs/tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 79a47f6

Please sign in to comment.