-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·67 lines (57 loc) · 1.82 KB
/
index.js
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
#!/usr/bin/env node
import { $ } from "zx"
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import chalk from "chalk"
import ora from "ora"
$.verbose = false
const airport =
"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
const startWifi = async () => {
await $`networksetup -setairportpower en1 on`
console.log("🚀 WiFi started.")
}
const stopWifi = async () => {
await $`networksetup -setairportpower en1 off`
console.log("🚫 WiFi stopped.")
}
const restartWifi = async () => {
await $`networksetup -setairportpower en1 off`
await $`networksetup -setairportpower en1 on`
console.log("🔄 WiFi restarted.")
}
const listSsid = async () => {
const spinner = ora("Loading networks...").start()
spinner.color = "blue"
const result = await $`${airport} scan`
spinner.stop()
console.log("")
console.log(result.stdout)
}
const showNetworkInfo = async () => {
const info = await $`${airport} -I`
console.log("")
console.log(info.stdout)
}
yargs(hideBin(process.argv))
.scriptName(chalk.cyan("wifi-tool"))
.usage(chalk.white("Usage: $0 [<command>|--help]"))
.command("start", chalk.black("Start WiFi"), {}, startWifi)
.command("stop", chalk.black("Stop WiFi"), {}, stopWifi)
.command("restart", chalk.black("Restart WiFi"), {}, restartWifi)
.command("list", chalk.black("List SSID"), {}, listSsid)
.command("info", chalk.black("Show network information"), {}, showNetworkInfo)
.demandCommand(1, "")
.help()
.version("1.0.0")
.epilogue(chalk.yellow("For more information, check out the documentation."))
.fail((msg, err, yargsInstance) => {
if (!msg) {
yargsInstance.showHelp()
process.exit(0)
}
if (err) throw err
console.error(chalk.red("Error!"))
console.error(chalk.red(msg))
process.exit(1)
}).argv