-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this change adds: - the default yargs completions for commands, options, etc. - custom completions for profiles (given that you have a config specified) - custom completions for database path (given that you have specified enough information to make a request to fauna)
- Loading branch information
1 parent
2071e2e
commit dbf877f
Showing
9 changed files
with
364 additions
and
29 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
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
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,46 @@ | ||
// @ts-check | ||
|
||
import * as path from "node:path"; | ||
|
||
import { FaunaAccountClient } from "../lib/fauna-account-client.mjs"; | ||
import { buildCredentials } from "./auth/credentials.mjs"; | ||
import { getConfig, locateConfig } from "./config/config.mjs"; | ||
|
||
export function getProfileCompletions(currentWord, argv) { | ||
const configPath = locateConfig(path.resolve(argv.config)); | ||
if (!configPath) return undefined; | ||
return Object.keys(getConfig(configPath).toJSON()); | ||
} | ||
|
||
export async function getDbCompletions(currentWord, argv) { | ||
const regionGroups = ["us-std", "eu-std", "global"]; | ||
|
||
function getRegionGroup(currentWord) { | ||
const rg = regionGroups.filter((rg) => currentWord.startsWith(rg)); | ||
return rg.length ? rg[0] : undefined; | ||
} | ||
|
||
if (!getRegionGroup(currentWord)) { | ||
return regionGroups; | ||
} else { | ||
const { pageSize } = argv; | ||
buildCredentials({ ...argv, user: "default" }); | ||
const accountClient = new FaunaAccountClient(); | ||
try { | ||
const response = await accountClient.listDatabases({ | ||
pageSize, | ||
path: currentWord, | ||
}); | ||
return response.results.map(({ name }) => path.join(currentWord, name)); | ||
} catch (e) { | ||
const response = await accountClient.listDatabases({ | ||
pageSize, | ||
// TO-DO: needs to handle aliases, does not | ||
path: path.dirname(currentWord), | ||
}); | ||
return response.results.map(({ name }) => | ||
path.join(path.dirname(currentWord), name), | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.