Skip to content

Commit

Permalink
change to if/else statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Sep 9, 2024
1 parent ccc2229 commit dc901ac
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions cli/commands/caddy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ module.exports = function ({ program, run }) {
.description('lists all domains you have configured in caddy')
.option('--user', 'allows you to add a domain on behalf of a user (requires sudo)')
.action(async (options) => {
username = options?.user && !isAdmin
? (console.error("To change/see another user's domains, you'll need to use sudo or be root."), process.exit(1))
: options?.user;
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
process.exit(1)
} else if (options?.user) {
username = options.user
}
var domains = await utils.getDomains(username)
domains = domains.map(domain => `- ${domain.domain} (${domain.proxy})`).join("\n")
console.log(domains)
Expand All @@ -25,9 +28,12 @@ module.exports = function ({ program, run }) {
.option('--proxy', 'changes where the domain should be proxied to (advanced)')
.option('--user', "allows you to list a different user's domains (requires sudo)")
.action(async (domain, options) => {
username = options?.user && !isAdmin
? (console.error("To change/see another user's domains, you'll need to use sudo or be root."), process.exit(1))
: options?.user;
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
process.exit(1)
} else if (options?.user) {
username = options.user
}
if (!validator.isFQDN(domain)) {
console.error("This domain is not a valid domain name. Please choose a valid domain name.")
process.exit(1)
Expand Down Expand Up @@ -64,9 +70,12 @@ module.exports = function ({ program, run }) {
.description('removes a domain from caddy')
.option('--user', 'allows you to add a domain on behalf of a user (requires sudo)')
.action(async (domain, options) => {
username = options?.user && !isAdmin
? (console.error("To change/see another user's domains, you'll need to use sudo or be root."), process.exit(1))
: options?.user;
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
process.exit(1)
} else if (options?.user) {
username = options.user
}
if (!validator.isFQDN(domain)) {
console.error("This domain is not a valid domain name. Please choose a valid domain name.")
process.exit(1)
Expand Down

0 comments on commit dc901ac

Please sign in to comment.