feat: ls pretty-format
This commit is contained in:
parent
80b4028ec7
commit
7ba57c13ef
1 changed files with 34 additions and 23 deletions
49
app.ts
49
app.ts
|
@ -89,7 +89,8 @@ async function main() {
|
||||||
console.log("Logout successful! Credentials removed.");
|
console.log("Logout successful! Credentials removed.");
|
||||||
})
|
})
|
||||||
.command("list, ls", "List all OAuth2 applications")
|
.command("list, ls", "List all OAuth2 applications")
|
||||||
.action(async () => {
|
.option("--pretty, -p", "Pretty print the output")
|
||||||
|
.action(async (opt) => {
|
||||||
const credentials = await credentialManager.getCredentials();
|
const credentials = await credentialManager.getCredentials();
|
||||||
if (!credentials) return;
|
if (!credentials) return;
|
||||||
|
|
||||||
|
@ -102,14 +103,29 @@ async function main() {
|
||||||
console.log("No OAuth2 applications found.");
|
console.log("No OAuth2 applications found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (opt.pretty) {
|
||||||
console.log("OAuth2 applications:");
|
console.log("OAuth2 applications:");
|
||||||
console.log(apps.map(prettyOauth2Application).join("\n\n"));
|
console.log(apps.map(prettyOauth2Application).join("\n\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const maxNameLength = Math.max(...apps.map(app => app.name.length), 6);
|
||||||
|
console.log(apps.map(app => [
|
||||||
|
app.id.toString().padEnd(5),
|
||||||
|
app.confidential_client ? "c" : "o",
|
||||||
|
app.name.padStart(maxNameLength),
|
||||||
|
app.client_id,
|
||||||
|
app.redirect_uris.join(", "),
|
||||||
|
].join(" ").trim()).join("\n"));
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.command("create", "Create new OAuth2 application")
|
.command("create", "Create new OAuth2 application")
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
const credentials = await credentialManager.getCredentials();
|
const credentials = await credentialManager.getCredentials();
|
||||||
if (!credentials) return;
|
if (!credentials) {
|
||||||
|
console.error("Credentials not found. Please login first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create OAuth2Api with token
|
// Create OAuth2Api with token
|
||||||
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
||||||
|
@ -142,33 +158,28 @@ async function main() {
|
||||||
await saveSecretKeys(path, app.client_id, app.client_secret);
|
await saveSecretKeys(path, app.client_id, app.client_secret);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.command("delete", "Delete OAuth2 application")
|
.command("remove, rm", "Remove OAuth2 application")
|
||||||
.action(async () => {
|
.arguments("<id:number>")
|
||||||
|
.action(async (_opt, appId) => {
|
||||||
const credentials = await credentialManager.getCredentials();
|
const credentials = await credentialManager.getCredentials();
|
||||||
if (!credentials) return;
|
if (!credentials) {
|
||||||
|
console.error("Credentials not found. Please login first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create OAuth2Api with token
|
// Create OAuth2Api with token
|
||||||
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
||||||
|
|
||||||
const id = await prompt("Enter the ID of the application to delete: ");
|
|
||||||
if (!id) {
|
|
||||||
console.error("ID is required.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const appId = parseInt(id);
|
|
||||||
if (isNaN(appId)) {
|
|
||||||
console.error("ID must be a number.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await oauth2Api.deleteOauth2Application(appId);
|
await oauth2Api.deleteOauth2Application(appId);
|
||||||
console.log("OAuth2 application deleted successfully!");
|
console.log("OAuth2 application deleted successfully!");
|
||||||
})
|
})
|
||||||
.command("update", "Update OAuth2 application")
|
.command("update", "Update OAuth2 application")
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
const credentials = await credentialManager.getCredentials();
|
const credentials = await credentialManager.getCredentials();
|
||||||
if (!credentials) return;
|
if (!credentials) {
|
||||||
|
console.error("Credentials not found. Please login first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create OAuth2Api with token
|
// Create OAuth2Api with token
|
||||||
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
const oauth2Api = new OAuth2Api(URL_BASE, credentials.token);
|
||||||
|
|
Loading…
Add table
Reference in a new issue