Skip to content

Commit

Permalink
Merge pull request #65 from hackclub/improve-js-cli
Browse files Browse the repository at this point in the history
Make the CLI actually work
  • Loading branch information
dispherical authored Sep 10, 2024
2 parents 99c778c + 1ce7675 commit eff8854
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cli/caddy_migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ routes.forEach(route => {
}
});
async function main() {
await prisma.domain.create({
await prisma.domain.createMany({
data: set
})
}
Expand Down
8 changes: 4 additions & 4 deletions cli/commands/caddy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function ({ program, run }) {
caddy
.command('list')
.description('lists all domains you have configured in caddy')
.option('--user', 'allows you to add a domain on behalf of a user (requires sudo)')
.option('--user [user]', 'allows you to add a domain on behalf of a user (requires sudo)')
.action(async (options) => {
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
Expand All @@ -25,8 +25,8 @@ module.exports = function ({ program, run }) {
caddy
.command('add <domain>')
.description('adds a domain to caddy')
.option('--proxy', 'changes where the domain should be proxied to (advanced)')
.option('--user', "allows you to list a different user's domains (requires sudo)")
.option('--proxy [proxy]', 'changes where the domain should be proxied to (advanced)')
.option('--user [user]', "allows you to list a different user's domains (requires sudo)")
.action(async (domain, options) => {
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = function ({ program, run }) {
caddy
.command('rm <domain>')
.description('removes a domain from caddy')
.option('--user', 'allows you to add a domain on behalf of a user (requires sudo)')
.option('--user [user]', 'allows you to add a domain on behalf of a user (requires sudo)')
.action(async (domain, options) => {
if (options?.user && !isAdmin) {
console.error("To change/see another user's domains, you'll need to use sudo or be root.")
Expand Down
4 changes: 4 additions & 0 deletions cli/commands/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module.exports = function ({ program, run }) {
.command('resources')
.description('See your Nest resource usage and limits')
.action(() => {
if (!process.getuid()){
console.log("Root doesn't have any limits.")
process.exit(0)
}
const output = run(`quota`).toString();
const numbers = output.split("\n").find(line => line.includes("/dev/sda")).match(/\d+/g);
const array = numbers.map(Number)
Expand Down
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
const { Command } = require('commander');
const program = new Command();
const { execSync } = require('child_process');
Expand Down
4 changes: 2 additions & 2 deletions cli/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ generator client {
}

datasource db {
provider = "sqlite"
url = "file:./database.sqlite"
provider = "postgresql"
url = env("DATABASE_URL")
}

model Domain {
Expand Down
5 changes: 2 additions & 3 deletions cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const isAdmin = !process.getuid() || os.userInfo().username == "nest-internal"

module.exports = {
checkWhitelist: function (domain, username) {
if (!fs.existsSync(".whitelist")) return
const whitelist = fs.readFileSync(".whitelist", "utf8").split("\n")
if (!fs.existsSync(__dirname + "/.whitelist")) return
const whitelist = fs.readFileSync(__dirname + "/.whitelist", "utf8").split("\n")

whitelist
var i = 0
while (i < whitelist.length) {
if (minimatch(domain, whitelist[i].replace("$USERNAME", username))) return true
Expand Down

0 comments on commit eff8854

Please sign in to comment.