-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from RoboVault/feat/cli-qol-fixes
Feat/cli qol fixes
- Loading branch information
Showing
23 changed files
with
639 additions
and
868 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ import { | |
Command, | ||
deploy, | ||
init, | ||
keygen, | ||
keyls, | ||
keyrm, | ||
list, | ||
login, | ||
logout, | ||
|
@@ -14,7 +17,7 @@ import { | |
} from './cli/mod.ts' | ||
import 'https://deno.land/[email protected]/dotenv/load.ts' | ||
|
||
export const version = 'v0.4.15' | ||
export const version = 'v0.4.16' | ||
|
||
const command = new Command() | ||
.name('arkiver') | ||
|
@@ -88,6 +91,7 @@ command | |
.option('--log-level <logLevel:string>', 'Log level', { | ||
default: 'INFO', | ||
}) | ||
.option('--gql-only', 'Only start GraphQL server') | ||
.action(async (opts, ...args) => { | ||
util.logHeader(version) | ||
await checkVersion(version) | ||
|
@@ -111,11 +115,30 @@ command | |
// list | ||
command | ||
.command('list', 'List all your arkives') | ||
.action(async () => { | ||
.option('-A, --all', 'List all arkives') | ||
.option('-s, --status <status>', 'Filter by status') | ||
.action(async (opts) => { | ||
await checkVersion(version) | ||
await list.action() | ||
await list.action(opts) | ||
}) | ||
|
||
// keygen | ||
command | ||
.command('keygen', 'Generate a new API key') | ||
.action(keygen.action) | ||
|
||
// keyrm | ||
command | ||
.command('keyrm', 'Delete an API key') | ||
.arguments('<key:string>') | ||
.action(async (_, key) => { | ||
await keyrm.action(key) | ||
}) | ||
|
||
command | ||
.command('keyls', 'List all API keys') | ||
.action(keyls.action) | ||
|
||
if (import.meta.main) { | ||
await command.parse(Deno.args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { spinner } from '../spinner.ts' | ||
|
||
export const cleanup = async (tempPath: string) => { | ||
spinner().text = 'Cleaning up...' | ||
await Deno.remove(tempPath, { recursive: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import { join } from 'https://deno.land/[email protected]/path/mod.ts' | ||
import { $ } from '../deps.ts' | ||
import { spinner } from '../spinner.ts' | ||
|
||
export const pkg = async (dir: string) => { | ||
const tempPath = await Deno.makeTempDir() | ||
const fileName = crypto.randomUUID() + '.tar.gz' | ||
const out = join(tempPath, fileName) | ||
spinner().text = 'Packaging...' | ||
try { | ||
const tempPath = await Deno.makeTempDir() | ||
const fileName = crypto.randomUUID() + '.tar.gz' | ||
const out = join(tempPath, fileName) | ||
|
||
const process = Deno.run({ | ||
cmd: ['tar', '-zcvf', out, '-C', dir, '.'], | ||
stdout: 'piped', | ||
stderr: 'piped', | ||
}) | ||
await $`tar -zcvf ${out} -C ${dir} .` | ||
|
||
const [status, err] = await Promise.all([ | ||
process.status(), | ||
process.stderrOutput(), | ||
]) | ||
if (status.code !== 0) { | ||
const errMsg = `Failed to build package: ${new TextDecoder().decode(err)}` | ||
throw new Error(errMsg) | ||
return { fileName, tempPath } | ||
} catch (error) { | ||
spinner().fail('Packaging failed: ' + error) | ||
Deno.exit(1) | ||
} | ||
|
||
process.close() | ||
|
||
return { fileName, tempPath } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
export { z } from 'https://esm.sh/[email protected]' | ||
export { Command } from 'https://deno.land/x/cliffy@v0.25.7/command/mod.ts' | ||
export { Command } from 'https://deno.land/x/cliffy@v1.0.0-rc.1/command/mod.ts' | ||
export { | ||
Input, | ||
prompt, | ||
Secret, | ||
Select, | ||
Toggle, | ||
} from 'https://deno.land/x/cliffy@v0.25.7/prompt/mod.ts' | ||
} from 'https://deno.land/x/cliffy@v1.0.0-rc.1/prompt/mod.ts' | ||
export { | ||
createClient, | ||
SupabaseClient, | ||
} from 'https://esm.sh/@supabase/[email protected]' | ||
export { wait } from 'https://deno.land/x/[email protected].12/mod.ts' | ||
export { Spinner, wait } from 'https://deno.land/x/[email protected].13/mod.ts' | ||
export { default as $ } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { delay } from 'https://deno.land/[email protected]/async/mod.ts' | ||
export { join } from 'https://deno.land/[email protected]/path/mod.ts' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { spinner } from '../spinner.ts' | ||
import { getSupabaseClient } from '../utils.ts' | ||
|
||
export const action = async (key: string) => { | ||
spinner(`Deleting key ${key}`) | ||
|
||
const client = getSupabaseClient() | ||
|
||
const { error } = await client.functions.invoke('api-key', { | ||
method: 'DELETE', | ||
body: { | ||
apiKey: key, | ||
}, | ||
}) | ||
|
||
if (error) { | ||
spinner().fail(`Failed to delete key: ${error.message}`) | ||
return | ||
} | ||
|
||
spinner().succeed(`Successfully deleted key: ${key}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { spinner } from '../spinner.ts' | ||
import { getSupabaseClient } from '../utils.ts' | ||
|
||
export const action = async () => { | ||
spinner('Fetching API keys') | ||
|
||
const client = getSupabaseClient() | ||
|
||
const { data, error } = await client.functions.invoke<{ api_key: string }[]>( | ||
'api-key', | ||
{ | ||
method: 'GET', | ||
}, | ||
) | ||
|
||
if (error) { | ||
spinner().fail(`Failed to fetch keys: ${error.message}`) | ||
return | ||
} | ||
|
||
if (!data) { | ||
spinner().fail(`Failed to fetch keys: no data returned`) | ||
return | ||
} | ||
|
||
spinner().succeed(`Successfully fetched keys:`) | ||
|
||
console.table(data.map((d) => ({ key: d.api_key }))) | ||
} |
Oops, something went wrong.