diff --git a/src/functions/domains.js b/src/functions/domains.js new file mode 100644 index 0000000..24a7bb1 --- /dev/null +++ b/src/functions/domains.js @@ -0,0 +1,26 @@ +const Conf = require("conf"); +const fetch = require("node-fetch"); + +const account = new Conf(); + +module.exports = async function domains() { + if(!account.has("username")) { + console.log("You are not logged in!"); + console.log("To log in, run the command: `domains login`"); + return; + } + + console.log(`Username: ${account.get("username")}`); + console.log(`Email: ${account.get("email")}\n`); + + const email = account.get("email"); + + const res = await fetch(`https://api.freesubdomains.org/lookup/user?email=${email}`); + + if(res.status === 500) return console.log("An error occurred, please try again later."); + if(res.status === 404) return console.log("You do not own any domains."); + + const domains = res.subdomains; + + return console.log(`Your Domains:\n${domains.join("\n")}`); +} diff --git a/src/index.js b/src/index.js index 70562de..0c0c0cb 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,7 @@ const { clear, debug } = flags; input.includes("account") && functions.account(); input.includes("check") && functions.check(); + input.includes("domains") && functions.domains(); input.includes("help") && cli.showHelp(0); input.includes("login") && functions.login(); input.includes("logout") && functions.logout(); diff --git a/src/util/cli.js b/src/util/cli.js index 4634725..6fa21fa 100644 --- a/src/util/cli.js +++ b/src/util/cli.js @@ -30,6 +30,7 @@ const flags = { const commands = { account: { desc: "Get information about your account." }, check: { desc: "Check if a subdomain is available." }, + domains: { desc: "Get a list of all your domains." }, login: { desc: "Login to your GitHub account." }, logout: { desc: "Logout of your GitHub account." }, register: { desc: "Register a subdomain." }, diff --git a/src/util/functions.js b/src/util/functions.js index cab0d54..40d13f2 100644 --- a/src/util/functions.js +++ b/src/util/functions.js @@ -1,6 +1,7 @@ module.exports = { "account": require("../functions/account"), "check": require("../functions/check"), + "domains": require("../functions/domains"), "login": require("../functions/login"), "logout": require("../functions/logout"), "register": require("../functions/register"),