-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
64 lines (55 loc) · 2.11 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { ControlBaseCommand } from '../../control-base-command.js'
// Track execution in each process run, not globally across all runs
const executionTracker = new class {
private isExecuting = false;
private lastExecutionTimestamp = 0;
done(): void {
this.isExecuting = false;
}
shouldExecute(): boolean {
// If we're already in an execution, don't run again
if (this.isExecuting) return false;
// If this is the first execution or if more than 1 second has passed since the last execution
// (to avoid issues with rapid sequential command execution), allow execution
const now = Date.now();
if (now - this.lastExecutionTimestamp > 1000) {
this.isExecuting = true;
this.lastExecutionTimestamp = now;
return true;
}
return false;
}
}();
export default class AccountsCommand extends ControlBaseCommand {
static description = 'Manage Ably accounts and your configured access tokens'
static examples = [
'ably accounts login',
'ably accounts list',
'ably accounts current',
'ably accounts logout',
'ably accounts switch my-account',
'ably accounts stats',
]
async run(): Promise<void> {
// Check if we should execute this command to avoid duplication
if (!executionTracker.shouldExecute()) {
return;
}
try {
// Continue with normal execution
this.log('Ably accounts management commands:')
this.log('')
this.log(' ably accounts login - Log in to your Ably account')
this.log(' ably accounts list - List all configured accounts')
this.log(' ably accounts current - Show the currently selected account')
this.log(' ably accounts logout - Log out from your Ably account')
this.log(' ably accounts switch - Switch to a different account')
this.log(' ably accounts stats - Get account stats with optional live updates')
this.log('')
this.log('Run `ably accounts COMMAND --help` for more information on a command.')
} finally {
// Mark execution as complete
executionTracker.done();
}
}
}