Highly ambitious ATProtocol AppView service and sdks
1import { parseArgs } from "@std/cli/parse-args";
2import { ConfigManager } from "../auth/config.ts";
3
4function showStatusHelp() {
5 console.log(`
6slices status - Show authentication and configuration status
7
8USAGE:
9 slices status [OPTIONS]
10
11OPTIONS:
12 -h, --help Show this help message
13
14EXAMPLES:
15 slices status
16`);
17}
18
19export async function statusCommand(commandArgs: unknown[], _globalArgs: Record<string, unknown>): Promise<void> {
20 const args = parseArgs(commandArgs as string[], {
21 boolean: ["help"],
22 alias: {
23 h: "help",
24 },
25 });
26
27 if (args.help) {
28 showStatusHelp();
29 return;
30 }
31
32 const config = new ConfigManager();
33 await config.load();
34
35 if (config.isAuthenticated()) {
36 const authConfig = config.get().auth!;
37
38 console.log(`Authenticated as ${authConfig.did}`);
39 console.log(`API: ${config.get().apiBaseUrl}`);
40
41 if (authConfig.expiresAt) {
42 const expiresIn = Math.round((authConfig.expiresAt - Date.now()) / 1000);
43 if (expiresIn > 0) {
44 const hours = Math.floor(expiresIn / 3600);
45 const minutes = Math.floor((expiresIn % 3600) / 60);
46
47 if (hours > 0) {
48 console.log(`Token expires in ${hours}h ${minutes}m`);
49 } else if (minutes > 0) {
50 console.log(`Token expires in ${minutes}m`);
51 } else {
52 console.log(`Token expires in ${expiresIn}s`);
53 }
54 } else {
55 console.log("Token has expired - run 'slices login' to re-authenticate");
56 }
57 }
58 } else {
59 console.log("Not authenticated - run 'slices login' to authenticate");
60 }
61}