-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·92 lines (82 loc) · 2.64 KB
/
index.js
File metadata and controls
executable file
·92 lines (82 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
// HTTP status code Lookup tool
// developed by @devfloww
// Importing dependencies
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
// Importing dependent files
import { showBanner } from "./src/Banner.js"
import { LoadDataShort, LoadDataLong } from "./src/LoadData.js"
import { DisplayShort } from "./src/DisplayShort.js"
import { DisplayLong } from "./src/DisplayLong.js"
import { Remove } from "./src/uninstall.js"
import { UpdateApp } from "./src/UpdateApp.js"
// Importing helper functions
import { sanitize_status_code_h } from "./src/helper_functions/sanitize_status_code.js"
import { checkInternetConnection } from "./src/helper_functions/checkInternetConnection_h.js"
import { failure } from "./src/helper_functions/Tags.js"
// Collect input params from the user and creating the options
const parser = yargs(hideBin(process.argv))
.option("help", {
alias: "h",
type: "boolean",
description: "Show help menu",
})
.option("code", {
alias: "c",
type: "number",
describe: "HTTP status code to lookup",
})
.option("long", {
alias: "l",
type: "boolean",
describe: "Provide a Long description of the staus code",
})
.option("remove", {
alias: "r",
type: "boolean",
describe: "Remove the tool from the computer",
})
.option("update", {
alias: "u",
type: "boolean",
describe: "Update the tool to the latest version",
})
// parsing the arguments
const args = parser.parse()
// Check to see if user wants to Uninstall the app
if (args.remove || args.r) {
// Remove the application
Remove()
}
// Check if user wants to update application
if (args.update || args.u) {
// Update to the latest version available on npm repo
checkInternetConnection(isConnected => {
if (isConnected) {
UpdateApp()
} else {
console.log(`${failure} No internet connection. Please check your connection and try again.`)
}
})
}
// Check to see if no arguments were supplied
if (!(args.code || args.help || args.remove || args.update || args.long || args.short)) {
// show banner and request to update the local cache
console.log(`\n${showBanner()}`)
// TODO: implement the updateLocalCache function and usi it
}
// check if status code was supplied by user
if (args.code || args.c) {
const sanitized_code = sanitize_status_code_h(args.code)
// check if the long flag is enabled
if (args.long && args.l) {
// display the long version
const code_data = LoadDataLong(sanitized_code)
DisplayLong(code_data)
} else {
// else just display the short version
const code_data = LoadDataShort(sanitized_code)
DisplayShort(code_data)
}
}