@hesed/gchat 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -24
- package/dist/commands/gchat/config/add-token.d.ts +1 -0
- package/dist/commands/gchat/config/add-token.js +7 -4
- package/dist/commands/gchat/config/set-key.d.ts +1 -0
- package/dist/commands/gchat/config/set-key.js +12 -4
- package/dist/commands/gchat/create-message.d.ts +1 -0
- package/dist/commands/gchat/create-message.js +12 -2
- package/dist/commands/gchat/reply-message.d.ts +1 -0
- package/dist/commands/gchat/reply-message.js +12 -2
- package/dist/config.d.ts +4 -3
- package/dist/config.js +24 -4
- package/oclif.manifest.json +38 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ $ npm install -g @hesed/gchat
|
|
|
26
26
|
$ gchat COMMAND
|
|
27
27
|
running command...
|
|
28
28
|
$ gchat (--version)
|
|
29
|
-
@hesed/gchat/0.
|
|
29
|
+
@hesed/gchat/0.3.0 linux-x64 node-v24.18.0
|
|
30
30
|
$ gchat --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ gchat COMMAND
|
|
@@ -37,51 +37,55 @@ USAGE
|
|
|
37
37
|
# Commands
|
|
38
38
|
|
|
39
39
|
<!-- commands -->
|
|
40
|
-
* [`gchat gchat config add-token SPACEID TOKEN`](#gchat-gchat-config-add-token-spaceid-token)
|
|
41
|
-
* [`gchat gchat config set-key KEY`](#gchat-gchat-config-set-key-key)
|
|
40
|
+
* [`gchat gchat config add-token PROFILE SPACEID TOKEN`](#gchat-gchat-config-add-token-profile-spaceid-token)
|
|
41
|
+
* [`gchat gchat config set-key PROFILE KEY`](#gchat-gchat-config-set-key-profile-key)
|
|
42
42
|
* [`gchat gchat create-message SPACEID MESSAGE`](#gchat-gchat-create-message-spaceid-message)
|
|
43
43
|
* [`gchat gchat reply-message THREADNAME MESSAGE`](#gchat-gchat-reply-message-threadname-message)
|
|
44
44
|
|
|
45
|
-
## `gchat gchat config add-token SPACEID TOKEN`
|
|
45
|
+
## `gchat gchat config add-token PROFILE SPACEID TOKEN`
|
|
46
46
|
|
|
47
|
-
Add or update an API token for a Google Chat space
|
|
47
|
+
Add or update an API token for a Google Chat space within a profile
|
|
48
48
|
|
|
49
49
|
```
|
|
50
50
|
USAGE
|
|
51
|
-
$ gchat gchat config add-token SPACEID TOKEN
|
|
51
|
+
$ gchat gchat config add-token PROFILE SPACEID TOKEN
|
|
52
52
|
|
|
53
53
|
ARGUMENTS
|
|
54
|
+
PROFILE Config profile name
|
|
54
55
|
SPACEID Google Chat space ID
|
|
55
56
|
TOKEN API token for this space
|
|
56
57
|
|
|
57
58
|
DESCRIPTION
|
|
58
|
-
Add or update an API token for a Google Chat space
|
|
59
|
+
Add or update an API token for a Google Chat space within a profile
|
|
59
60
|
|
|
60
61
|
EXAMPLES
|
|
61
|
-
$ gchat gchat config add-token AAQAKA6hsFw your-space-token
|
|
62
|
+
$ gchat gchat config add-token default AAQAKA6hsFw your-space-token
|
|
62
63
|
```
|
|
63
64
|
|
|
64
|
-
_See code: [src/commands/gchat/config/add-token.ts](https://github.com/hesedcasa/gchat/blob/v0.
|
|
65
|
+
_See code: [src/commands/gchat/config/add-token.ts](https://github.com/hesedcasa/gchat/blob/v0.3.0/src/commands/gchat/config/add-token.ts)_
|
|
65
66
|
|
|
66
|
-
## `gchat gchat config set-key KEY`
|
|
67
|
+
## `gchat gchat config set-key PROFILE KEY`
|
|
67
68
|
|
|
68
|
-
Set the Google Chat API key
|
|
69
|
+
Set the Google Chat API key for a profile
|
|
69
70
|
|
|
70
71
|
```
|
|
71
72
|
USAGE
|
|
72
|
-
$ gchat gchat config set-key KEY
|
|
73
|
+
$ gchat gchat config set-key PROFILE KEY
|
|
73
74
|
|
|
74
75
|
ARGUMENTS
|
|
75
|
-
|
|
76
|
+
PROFILE Config profile name
|
|
77
|
+
KEY Google Chat API key
|
|
76
78
|
|
|
77
79
|
DESCRIPTION
|
|
78
|
-
Set the Google Chat API key
|
|
80
|
+
Set the Google Chat API key for a profile
|
|
79
81
|
|
|
80
82
|
EXAMPLES
|
|
81
|
-
$ gchat gchat config set-key your-api-key
|
|
83
|
+
$ gchat gchat config set-key default your-api-key
|
|
84
|
+
|
|
85
|
+
$ gchat gchat config set-key work your-work-api-key
|
|
82
86
|
```
|
|
83
87
|
|
|
84
|
-
_See code: [src/commands/gchat/config/set-key.ts](https://github.com/hesedcasa/gchat/blob/v0.
|
|
88
|
+
_See code: [src/commands/gchat/config/set-key.ts](https://github.com/hesedcasa/gchat/blob/v0.3.0/src/commands/gchat/config/set-key.ts)_
|
|
85
89
|
|
|
86
90
|
## `gchat gchat create-message SPACEID MESSAGE`
|
|
87
91
|
|
|
@@ -89,15 +93,16 @@ Send a message to a Google Chat space
|
|
|
89
93
|
|
|
90
94
|
```
|
|
91
95
|
USAGE
|
|
92
|
-
$ gchat gchat create-message SPACEID MESSAGE [-f] [--toon]
|
|
96
|
+
$ gchat gchat create-message SPACEID MESSAGE [-f] [-p <value>] [--toon]
|
|
93
97
|
|
|
94
98
|
ARGUMENTS
|
|
95
99
|
SPACEID Google Chat space ID
|
|
96
100
|
MESSAGE Message text to send
|
|
97
101
|
|
|
98
102
|
FLAGS
|
|
99
|
-
-f, --formatted
|
|
100
|
-
|
|
103
|
+
-f, --formatted Enable formatted text (bold, italic, links)
|
|
104
|
+
-p, --profile=<value> [default: default] Config profile to use
|
|
105
|
+
--toon Format output as toon
|
|
101
106
|
|
|
102
107
|
DESCRIPTION
|
|
103
108
|
Send a message to a Google Chat space
|
|
@@ -105,12 +110,14 @@ DESCRIPTION
|
|
|
105
110
|
EXAMPLES
|
|
106
111
|
$ gchat gchat create-message AAQAKA6hsFw "Hello team"
|
|
107
112
|
|
|
113
|
+
$ gchat gchat create-message AAQAKA6hsFw "Hello work" --profile work
|
|
114
|
+
|
|
108
115
|
$ gchat gchat create-message AAQAKA6hsFw "*Bold message*" --formatted
|
|
109
116
|
|
|
110
117
|
$ gchat gchat create-message AAQAKA6hsFw "<https://example.com|Click here>" -f
|
|
111
118
|
```
|
|
112
119
|
|
|
113
|
-
_See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.
|
|
120
|
+
_See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.0/src/commands/gchat/create-message.ts)_
|
|
114
121
|
|
|
115
122
|
## `gchat gchat reply-message THREADNAME MESSAGE`
|
|
116
123
|
|
|
@@ -118,15 +125,16 @@ Reply to a message thread in Google Chat
|
|
|
118
125
|
|
|
119
126
|
```
|
|
120
127
|
USAGE
|
|
121
|
-
$ gchat gchat reply-message THREADNAME MESSAGE [-f] [--toon]
|
|
128
|
+
$ gchat gchat reply-message THREADNAME MESSAGE [-f] [-p <value>] [--toon]
|
|
122
129
|
|
|
123
130
|
ARGUMENTS
|
|
124
131
|
THREADNAME Thread name (e.g. spaces/SPACE_ID/threads/THREAD_ID)
|
|
125
132
|
MESSAGE Message text to send
|
|
126
133
|
|
|
127
134
|
FLAGS
|
|
128
|
-
-f, --formatted
|
|
129
|
-
|
|
135
|
+
-f, --formatted Enable formatted text (bold, italic, links)
|
|
136
|
+
-p, --profile=<value> [default: default] Config profile to use
|
|
137
|
+
--toon Format output as toon
|
|
130
138
|
|
|
131
139
|
DESCRIPTION
|
|
132
140
|
Reply to a message thread in Google Chat
|
|
@@ -134,8 +142,10 @@ DESCRIPTION
|
|
|
134
142
|
EXAMPLES
|
|
135
143
|
$ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here"
|
|
136
144
|
|
|
145
|
+
$ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here" --profile work
|
|
146
|
+
|
|
137
147
|
$ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "*Bold reply*" --formatted
|
|
138
148
|
```
|
|
139
149
|
|
|
140
|
-
_See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.
|
|
150
|
+
_See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.0/src/commands/gchat/reply-message.ts)_
|
|
141
151
|
<!-- commandsstop -->
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
export default class ConfigAddToken extends Command {
|
|
3
3
|
static args: {
|
|
4
|
+
profile: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
4
5
|
spaceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
6
|
token: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
7
|
};
|
|
@@ -2,16 +2,19 @@ import { Args, Command } from '@oclif/core';
|
|
|
2
2
|
import { readConfigOrEmpty, writeConfig } from '../../../config.js';
|
|
3
3
|
export default class ConfigAddToken extends Command {
|
|
4
4
|
static args = {
|
|
5
|
+
profile: Args.string({ description: 'Config profile name', required: true }),
|
|
5
6
|
spaceId: Args.string({ description: 'Google Chat space ID', required: true }),
|
|
6
7
|
token: Args.string({ description: 'API token for this space', required: true }),
|
|
7
8
|
};
|
|
8
|
-
static description = 'Add or update an API token for a Google Chat space';
|
|
9
|
-
static examples = ['<%= config.bin %> <%= command.id %> AAQAKA6hsFw your-space-token'];
|
|
9
|
+
static description = 'Add or update an API token for a Google Chat space within a profile';
|
|
10
|
+
static examples = ['<%= config.bin %> <%= command.id %> default AAQAKA6hsFw your-space-token'];
|
|
10
11
|
async run() {
|
|
11
12
|
const { args } = await this.parse(ConfigAddToken);
|
|
12
13
|
const config = await readConfigOrEmpty(this.config.configDir);
|
|
13
|
-
config.
|
|
14
|
+
const profile = config.profiles[args.profile] ?? { key: '', tokens: {} };
|
|
15
|
+
profile.tokens[args.spaceId] = args.token;
|
|
16
|
+
config.profiles[args.profile] = profile;
|
|
14
17
|
await writeConfig(this.config.configDir, config);
|
|
15
|
-
this.log(`Token for space ${args.spaceId} updated successfully.`);
|
|
18
|
+
this.log(`Token for space ${args.spaceId} in profile '${args.profile}' updated successfully.`);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
export default class ConfigSetKey extends Command {
|
|
3
3
|
static args: {
|
|
4
|
+
profile: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
4
5
|
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
6
|
};
|
|
6
7
|
static description: string;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Args, Command } from '@oclif/core';
|
|
2
2
|
import { readConfigOrEmpty, writeConfig } from '../../../config.js';
|
|
3
3
|
export default class ConfigSetKey extends Command {
|
|
4
|
+
/* eslint-disable perfectionist/sort-objects */
|
|
4
5
|
static args = {
|
|
6
|
+
profile: Args.string({ description: 'Config profile name', required: true }),
|
|
5
7
|
key: Args.string({ description: 'Google Chat API key', required: true }),
|
|
6
8
|
};
|
|
7
|
-
|
|
8
|
-
static
|
|
9
|
+
/* eslint-enable perfectionist/sort-objects */
|
|
10
|
+
static description = 'Set the Google Chat API key for a profile';
|
|
11
|
+
static examples = [
|
|
12
|
+
'<%= config.bin %> <%= command.id %> default your-api-key',
|
|
13
|
+
'<%= config.bin %> <%= command.id %> work your-work-api-key',
|
|
14
|
+
];
|
|
9
15
|
async run() {
|
|
10
16
|
const { args } = await this.parse(ConfigSetKey);
|
|
11
17
|
const config = await readConfigOrEmpty(this.config.configDir);
|
|
12
|
-
config.
|
|
18
|
+
const profile = config.profiles[args.profile] ?? { key: '', tokens: {} };
|
|
19
|
+
profile.key = args.key;
|
|
20
|
+
config.profiles[args.profile] = profile;
|
|
13
21
|
await writeConfig(this.config.configDir, config);
|
|
14
|
-
this.log(
|
|
22
|
+
this.log(`API key for profile '${args.profile}' updated successfully.`);
|
|
15
23
|
}
|
|
16
24
|
}
|
|
@@ -8,6 +8,7 @@ export default class GChatCreateMessage extends Command {
|
|
|
8
8
|
static examples: string[];
|
|
9
9
|
static flags: {
|
|
10
10
|
formatted: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
13
|
};
|
|
13
14
|
run(): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
-
import { readConfig } from '../../config.js';
|
|
2
|
+
import { DEFAULT_PROFILE, readConfig, resolveProfile } from '../../config.js';
|
|
3
3
|
import { formatAsToon } from '../../format.js';
|
|
4
4
|
import { clearClients, newMessage } from '../../gchat/gchat-client.js';
|
|
5
5
|
export default class GChatCreateMessage extends Command {
|
|
@@ -12,11 +12,18 @@ export default class GChatCreateMessage extends Command {
|
|
|
12
12
|
static description = 'Send a message to a Google Chat space';
|
|
13
13
|
static examples = [
|
|
14
14
|
'<%= config.bin %> <%= command.id %> AAQAKA6hsFw "Hello team"',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> AAQAKA6hsFw "Hello work" --profile work',
|
|
15
16
|
'<%= config.bin %> <%= command.id %> AAQAKA6hsFw "*Bold message*" --formatted',
|
|
16
17
|
'<%= config.bin %> <%= command.id %> AAQAKA6hsFw "<https://example.com|Click here>" -f',
|
|
17
18
|
];
|
|
18
19
|
static flags = {
|
|
19
20
|
formatted: Flags.boolean({ char: 'f', description: 'Enable formatted text (bold, italic, links)', required: false }),
|
|
21
|
+
profile: Flags.string({
|
|
22
|
+
char: 'p',
|
|
23
|
+
default: DEFAULT_PROFILE,
|
|
24
|
+
description: 'Config profile to use',
|
|
25
|
+
required: false,
|
|
26
|
+
}),
|
|
20
27
|
toon: Flags.boolean({ description: 'Format output as toon', required: false }),
|
|
21
28
|
};
|
|
22
29
|
async run() {
|
|
@@ -24,8 +31,11 @@ export default class GChatCreateMessage extends Command {
|
|
|
24
31
|
const config = await readConfig(this.config.configDir, this.log.bind(this));
|
|
25
32
|
if (!config)
|
|
26
33
|
return;
|
|
34
|
+
const auth = resolveProfile(config, flags.profile, this.log.bind(this));
|
|
35
|
+
if (!auth)
|
|
36
|
+
return;
|
|
27
37
|
// eslint-disable-next-line unicorn/prefer-string-replace-all
|
|
28
|
-
const result = await newMessage(
|
|
38
|
+
const result = await newMessage(auth, args.spaceId, args.message.replace(/\\n/g, '\n'), flags.formatted);
|
|
29
39
|
clearClients();
|
|
30
40
|
if (flags.toon) {
|
|
31
41
|
this.log(formatAsToon(result));
|
|
@@ -8,6 +8,7 @@ export default class GChatReplyMessage extends Command {
|
|
|
8
8
|
static examples: string[];
|
|
9
9
|
static flags: {
|
|
10
10
|
formatted: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
13
|
};
|
|
13
14
|
run(): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
-
import { readConfig } from '../../config.js';
|
|
2
|
+
import { DEFAULT_PROFILE, readConfig, resolveProfile } from '../../config.js';
|
|
3
3
|
import { formatAsToon } from '../../format.js';
|
|
4
4
|
import { clearClients, replyMessage } from '../../gchat/gchat-client.js';
|
|
5
5
|
export default class GChatReplyMessage extends Command {
|
|
@@ -15,10 +15,17 @@ export default class GChatReplyMessage extends Command {
|
|
|
15
15
|
static description = 'Reply to a message thread in Google Chat';
|
|
16
16
|
static examples = [
|
|
17
17
|
'<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here"',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here" --profile work',
|
|
18
19
|
'<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "*Bold reply*" --formatted',
|
|
19
20
|
];
|
|
20
21
|
static flags = {
|
|
21
22
|
formatted: Flags.boolean({ char: 'f', description: 'Enable formatted text (bold, italic, links)', required: false }),
|
|
23
|
+
profile: Flags.string({
|
|
24
|
+
char: 'p',
|
|
25
|
+
default: DEFAULT_PROFILE,
|
|
26
|
+
description: 'Config profile to use',
|
|
27
|
+
required: false,
|
|
28
|
+
}),
|
|
22
29
|
toon: Flags.boolean({ description: 'Format output as toon', required: false }),
|
|
23
30
|
};
|
|
24
31
|
async run() {
|
|
@@ -26,8 +33,11 @@ export default class GChatReplyMessage extends Command {
|
|
|
26
33
|
const config = await readConfig(this.config.configDir, this.log.bind(this));
|
|
27
34
|
if (!config)
|
|
28
35
|
return;
|
|
36
|
+
const auth = resolveProfile(config, flags.profile, this.log.bind(this));
|
|
37
|
+
if (!auth)
|
|
38
|
+
return;
|
|
29
39
|
// eslint-disable-next-line unicorn/prefer-string-replace-all
|
|
30
|
-
const result = await replyMessage(
|
|
40
|
+
const result = await replyMessage(auth, args.threadName, args.message.replace(/\\n/g, '\n'), flags.formatted);
|
|
31
41
|
clearClients();
|
|
32
42
|
if (flags.toon) {
|
|
33
43
|
this.log(formatAsToon(result));
|
package/dist/config.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_PROFILE = "default";
|
|
1
2
|
export interface GChatAuth {
|
|
2
3
|
key: string;
|
|
3
4
|
tokens: Record<string, string>;
|
|
4
5
|
}
|
|
5
|
-
interface GChatConfig {
|
|
6
|
-
|
|
6
|
+
export interface GChatConfig {
|
|
7
|
+
profiles: Record<string, GChatAuth>;
|
|
7
8
|
}
|
|
8
9
|
export declare function readConfigOrEmpty(configDir: string): Promise<GChatConfig>;
|
|
9
10
|
export declare function writeConfig(configDir: string, config: GChatConfig): Promise<void>;
|
|
10
11
|
export declare function readConfig(configDir: string, log: (msg: string) => void): Promise<GChatConfig | null>;
|
|
11
|
-
export
|
|
12
|
+
export declare function resolveProfile(config: GChatConfig, profile: string, log: (msg: string) => void): GChatAuth | null;
|
package/dist/config.js
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
export const DEFAULT_PROFILE = 'default';
|
|
4
|
+
function parseProfiles(raw) {
|
|
5
|
+
if (raw.profiles && typeof raw.profiles === 'object') {
|
|
6
|
+
const profiles = {};
|
|
7
|
+
for (const [name, profile] of Object.entries(raw.profiles)) {
|
|
8
|
+
profiles[name] = { key: profile.key ?? '', tokens: profile.tokens ?? {} };
|
|
9
|
+
}
|
|
10
|
+
return profiles;
|
|
11
|
+
}
|
|
12
|
+
// Legacy single-profile config: promote top-level key/tokens to the default profile.
|
|
13
|
+
return { [DEFAULT_PROFILE]: { key: raw.key ?? '', tokens: raw.tokens ?? {} } };
|
|
14
|
+
}
|
|
3
15
|
export async function readConfigOrEmpty(configDir) {
|
|
4
16
|
const configPath = join(configDir, 'gchat-config.json');
|
|
5
17
|
try {
|
|
6
18
|
const raw = JSON.parse(await readFile(configPath, 'utf8'));
|
|
7
|
-
return {
|
|
19
|
+
return { profiles: parseProfiles(raw) };
|
|
8
20
|
}
|
|
9
21
|
catch {
|
|
10
|
-
return {
|
|
22
|
+
return { profiles: {} };
|
|
11
23
|
}
|
|
12
24
|
}
|
|
13
25
|
export async function writeConfig(configDir, config) {
|
|
14
26
|
const configPath = join(configDir, 'gchat-config.json');
|
|
15
27
|
await mkdir(configDir, { recursive: true });
|
|
16
|
-
await writeFile(configPath, JSON.stringify(config.
|
|
28
|
+
await writeFile(configPath, JSON.stringify({ profiles: config.profiles }, null, 2));
|
|
17
29
|
}
|
|
18
30
|
export async function readConfig(configDir, log) {
|
|
19
31
|
const configPath = join(configDir, 'gchat-config.json');
|
|
20
32
|
try {
|
|
21
33
|
const raw = JSON.parse(await readFile(configPath, 'utf8'));
|
|
22
|
-
return {
|
|
34
|
+
return { profiles: parseProfiles(raw) };
|
|
23
35
|
}
|
|
24
36
|
catch {
|
|
25
37
|
log(`Error: Could not read config from ${configPath}`);
|
|
@@ -27,3 +39,11 @@ export async function readConfig(configDir, log) {
|
|
|
27
39
|
return null;
|
|
28
40
|
}
|
|
29
41
|
}
|
|
42
|
+
export function resolveProfile(config, profile, log) {
|
|
43
|
+
const auth = config.profiles[profile];
|
|
44
|
+
if (!auth) {
|
|
45
|
+
log(`Error: Profile '${profile}' not found. Run 'gchat gchat config set-key ${profile} <key>' to create it.`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return auth;
|
|
49
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"description": "Send a message to a Google Chat space",
|
|
18
18
|
"examples": [
|
|
19
19
|
"<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"Hello team\"",
|
|
20
|
+
"<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"Hello work\" --profile work",
|
|
20
21
|
"<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"*Bold message*\" --formatted",
|
|
21
22
|
"<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"<https://example.com|Click here>\" -f"
|
|
22
23
|
],
|
|
@@ -29,6 +30,16 @@
|
|
|
29
30
|
"allowNo": false,
|
|
30
31
|
"type": "boolean"
|
|
31
32
|
},
|
|
33
|
+
"profile": {
|
|
34
|
+
"char": "p",
|
|
35
|
+
"description": "Config profile to use",
|
|
36
|
+
"name": "profile",
|
|
37
|
+
"required": false,
|
|
38
|
+
"default": "default",
|
|
39
|
+
"hasDynamicHelp": false,
|
|
40
|
+
"multiple": false,
|
|
41
|
+
"type": "option"
|
|
42
|
+
},
|
|
32
43
|
"toon": {
|
|
33
44
|
"description": "Format output as toon",
|
|
34
45
|
"name": "toon",
|
|
@@ -70,6 +81,7 @@
|
|
|
70
81
|
"description": "Reply to a message thread in Google Chat",
|
|
71
82
|
"examples": [
|
|
72
83
|
"<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA \"Reply here\"",
|
|
84
|
+
"<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA \"Reply here\" --profile work",
|
|
73
85
|
"<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA \"*Bold reply*\" --formatted"
|
|
74
86
|
],
|
|
75
87
|
"flags": {
|
|
@@ -81,6 +93,16 @@
|
|
|
81
93
|
"allowNo": false,
|
|
82
94
|
"type": "boolean"
|
|
83
95
|
},
|
|
96
|
+
"profile": {
|
|
97
|
+
"char": "p",
|
|
98
|
+
"description": "Config profile to use",
|
|
99
|
+
"name": "profile",
|
|
100
|
+
"required": false,
|
|
101
|
+
"default": "default",
|
|
102
|
+
"hasDynamicHelp": false,
|
|
103
|
+
"multiple": false,
|
|
104
|
+
"type": "option"
|
|
105
|
+
},
|
|
84
106
|
"toon": {
|
|
85
107
|
"description": "Format output as toon",
|
|
86
108
|
"name": "toon",
|
|
@@ -108,6 +130,11 @@
|
|
|
108
130
|
"gchat:config:add-token": {
|
|
109
131
|
"aliases": [],
|
|
110
132
|
"args": {
|
|
133
|
+
"profile": {
|
|
134
|
+
"description": "Config profile name",
|
|
135
|
+
"name": "profile",
|
|
136
|
+
"required": true
|
|
137
|
+
},
|
|
111
138
|
"spaceId": {
|
|
112
139
|
"description": "Google Chat space ID",
|
|
113
140
|
"name": "spaceId",
|
|
@@ -119,9 +146,9 @@
|
|
|
119
146
|
"required": true
|
|
120
147
|
}
|
|
121
148
|
},
|
|
122
|
-
"description": "Add or update an API token for a Google Chat space",
|
|
149
|
+
"description": "Add or update an API token for a Google Chat space within a profile",
|
|
123
150
|
"examples": [
|
|
124
|
-
"<%= config.bin %> <%= command.id %> AAQAKA6hsFw your-space-token"
|
|
151
|
+
"<%= config.bin %> <%= command.id %> default AAQAKA6hsFw your-space-token"
|
|
125
152
|
],
|
|
126
153
|
"flags": {},
|
|
127
154
|
"hasDynamicHelp": false,
|
|
@@ -144,15 +171,21 @@
|
|
|
144
171
|
"gchat:config:set-key": {
|
|
145
172
|
"aliases": [],
|
|
146
173
|
"args": {
|
|
174
|
+
"profile": {
|
|
175
|
+
"description": "Config profile name",
|
|
176
|
+
"name": "profile",
|
|
177
|
+
"required": true
|
|
178
|
+
},
|
|
147
179
|
"key": {
|
|
148
180
|
"description": "Google Chat API key",
|
|
149
181
|
"name": "key",
|
|
150
182
|
"required": true
|
|
151
183
|
}
|
|
152
184
|
},
|
|
153
|
-
"description": "Set the Google Chat API key
|
|
185
|
+
"description": "Set the Google Chat API key for a profile",
|
|
154
186
|
"examples": [
|
|
155
|
-
"<%= config.bin %> <%= command.id %> your-api-key"
|
|
187
|
+
"<%= config.bin %> <%= command.id %> default your-api-key",
|
|
188
|
+
"<%= config.bin %> <%= command.id %> work your-work-api-key"
|
|
156
189
|
],
|
|
157
190
|
"flags": {},
|
|
158
191
|
"hasDynamicHelp": false,
|
|
@@ -173,5 +206,5 @@
|
|
|
173
206
|
]
|
|
174
207
|
}
|
|
175
208
|
},
|
|
176
|
-
"version": "0.
|
|
209
|
+
"version": "0.3.0"
|
|
177
210
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hesed/gchat",
|
|
3
3
|
"description": "CLI for Google Chat API interaction",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"author": "Hesed",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gchat": "./bin/run.js"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/chai": "^5",
|
|
21
21
|
"@types/fs-extra": "^11.0.4",
|
|
22
22
|
"@types/mocha": "^10",
|
|
23
|
-
"@types/node": "^
|
|
23
|
+
"@types/node": "^26",
|
|
24
24
|
"@types/sinon": "^21.0.0",
|
|
25
25
|
"c8": "^11.0.0",
|
|
26
26
|
"chai": "^6",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"oclif": "^4",
|
|
33
33
|
"prettier": "^3.8.1",
|
|
34
34
|
"shx": "^0.4.0",
|
|
35
|
-
"sinon": "^
|
|
35
|
+
"sinon": "^22.0.0",
|
|
36
36
|
"ts-node": "^10",
|
|
37
37
|
"ts-prune": "^0.10.3",
|
|
38
38
|
"typescript": "^5"
|