Skip to content

Commit

Permalink
Merge pull request #386 from kisaragi-hiu/patch-1
Browse files Browse the repository at this point in the history
Resolve api_key_vault_cmd like wakatime-cli does
  • Loading branch information
alanhamlett authored Apr 10, 2024
2 parents e0a7f36 + 780bf90 commit 93dc02c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,21 @@ export class Options {

public async getApiKeyFromVaultCmd(): Promise<string> {
try {
const apiKeyCmd = await this.getSettingAsync<string>('settings', 'api_key_vault_cmd');
if (!apiKeyCmd) return '';
// Use basically the same logic as wakatime-cli to interpret cmdStr
// https://github.com/wakatime/wakatime-cli/blob/1fd560a/cmd/params/params.go#L697
let cmdStr = await this.getSettingAsync<string>('settings', 'api_key_vault_cmd');
if (!cmdStr) return '';

cmdStr = cmdStr.trim();
if (cmdStr === '') return '';

const cmdParts = cmdStr.split(" ");
if (cmdParts.length === 0) return '';

const [cmdName, ...cmdArgs] = cmdParts;

const options = Desktop.buildOptions();
const proc = child_process.spawn(apiKeyCmd, options);
const proc = child_process.spawn(cmdName, cmdArgs, options);

let stdout = '';
for await (const chunk of proc.stdout) {
Expand Down

0 comments on commit 93dc02c

Please sign in to comment.