Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
{
"extends": ["oclif", "oclif-typescript", "prettier"]
"extends": ["oclif", "oclif-typescript", "prettier"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"camelcase": "off",
"import/no-named-as-default-member": "off",
"no-await-in-loop": "off",
"no-template-curly-in-string": "off",
"node/no-extraneous-import": "off",
"node/no-extraneous-require": "off",
"perfectionist/sort-array-includes": "off",
"perfectionist/sort-classes": "off",
"perfectionist/sort-enums": "off",
"perfectionist/sort-imports": "off",
"perfectionist/sort-interfaces": "off",
"perfectionist/sort-named-exports": "off",
"perfectionist/sort-named-imports": "off",
"perfectionist/sort-object-types": "off",
"perfectionist/sort-objects": "off",
"perfectionist/sort-union-types": "off",
"unicorn/consistent-destructuring": "off",
"unicorn/consistent-function-scoping": "off",
"unicorn/filename-case": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-array-push-push": "off",
"unicorn/no-array-reduce": "off",
"unicorn/prefer-array-some": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-native-coercion-functions": "off",
"unicorn/prefer-spread": "off",
"unicorn/prefer-ternary": "off",
"unicorn/text-encoding-identifier-case": "off"
}
}
10 changes: 10 additions & 0 deletions meta-cli-init.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "../meta-cli-init"
},
{
"path": "."
}
]
}
24 changes: 15 additions & 9 deletions src/AWSProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ini from 'ini';
import os from 'os';
import fs from 'fs';
import { execSync } from 'child_process';
import os from 'node:os';
import fs from 'node:fs';
import { execSync } from 'node:child_process';

import {
RDSClient,
Expand Down Expand Up @@ -73,7 +73,7 @@ class AWSProvider implements Provider {
fs.writeFileSync(`${os.homedir}/.aws/config`, '')
}

const config = ini.parse(fs.readFileSync(`${os.homedir}/.aws/config`, 'utf-8'));
const config = ini.parse(fs.readFileSync(`${os.homedir}/.aws/config`, 'utf8'));

if(account.provider !== PROVIDER.AWS) {
return;
Expand Down Expand Up @@ -123,7 +123,7 @@ class AWSProvider implements Provider {
for (const cluster of clusters) {
clusterRegionMap[cluster] = region;
}
} catch (error) {
} catch {
continue;
}
}
Expand All @@ -136,10 +136,11 @@ class AWSProvider implements Provider {
const env = envOutput.split('\n').reduce((acc: any, item) => {
const indexOfEquals = item.indexOf('=');
if (indexOfEquals !== -1) {
const key = item.substring(0, indexOfEquals);
const value = item.substring(indexOfEquals + 1);
const key = item.slice(0, Math.max(0, indexOfEquals));
const value = item.slice(Math.max(0, indexOfEquals + 1));
acc[key] = value;
}

return acc;
}, {});

Expand All @@ -151,10 +152,11 @@ class AWSProvider implements Provider {
return output.split('\n').reduce((acc: any, item) => {
const indexOfEquals = item.indexOf('=');
if (indexOfEquals !== -1) {
const key = item.substring(0, indexOfEquals);
const value = item.substring(indexOfEquals + 1);
const key = item.slice(0, Math.max(0, indexOfEquals));
const value = item.slice(Math.max(0, indexOfEquals + 1));
acc[key] = value;
}

return acc;
}, {});
}
Expand Down Expand Up @@ -234,6 +236,7 @@ class AWSProvider implements Provider {
if(moduleName) {
data.moduleName = moduleName.Value;
}

if(moduleVersion) {
data.moduleVersion = moduleVersion.Value;
}
Expand Down Expand Up @@ -271,6 +274,7 @@ class AWSProvider implements Provider {
if(moduleName) {
data.moduleName = moduleName.Value;
}

if(moduleVersion) {
data.moduleVersion = moduleVersion.Value;
}
Expand Down Expand Up @@ -351,6 +355,7 @@ class AWSProvider implements Provider {
if(moduleName) {
data.moduleName = moduleName.Value;
}

if(moduleVersion) {
data.moduleVersion = moduleVersion.Value;
}
Expand Down Expand Up @@ -391,6 +396,7 @@ class AWSProvider implements Provider {
if(moduleName) {
data.moduleName = moduleName.Value;
}

if(moduleVersion) {
data.moduleVersion = moduleVersion.Value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/AzureProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'os';
import fs from 'fs';
import { execSync } from 'child_process';
import os from 'node:os';
import fs from 'node:fs';
import { execSync } from 'node:child_process';
import {
Account,
Component,
Expand Down
16 changes: 8 additions & 8 deletions src/GCPProvider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ini from 'ini';
import os from 'os';
import fs from 'fs';
import os from 'node:os';
import fs from 'node:fs';
import { omit, lowerCase } from 'lodash';
import { execSync } from 'child_process';
import { execSync } from 'node:child_process';
import { v1 } from '@google-cloud/sql';
import { Storage } from '@google-cloud/storage';

Expand Down Expand Up @@ -39,17 +39,17 @@ class GCPProvider implements Provider {
fs.writeFileSync(`${os.homedir}/.config/gcloud/configurations/config_${account.name}-${account.alias}`, '')
}

const config = ini.parse(fs.readFileSync(`${os.homedir}/.config/gcloud/configurations/config_${account.name}-${account.alias}`, 'utf-8'));
const config = ini.parse(fs.readFileSync(`${os.homedir}/.config/gcloud/configurations/config_${account.name}-${account.alias}`, 'utf8'));

if(account.provider !== PROVIDER.GCP) {
return;
}

config['core'] = {
config.core = {
'project': account.accountId
}

config['compute'] = {
config.compute = {
'zone': account.zone,
'region': account.region
}
Expand Down Expand Up @@ -125,8 +125,8 @@ class GCPProvider implements Provider {

try {
data = await instancesClient.list({ project });
} catch(e: any) {
console.log(e.message);
} catch(error: any) {
console.log(error.message);
}

const dbData: DbData[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/KubernetesProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os from 'os';
import os from 'node:os';
import { uniqBy } from 'lodash';
import * as k8s from '@kubernetes/client-node';
import { Account, Component, Environment, UNKNOWN_MODULE, ClusterData } from './types';
Expand All @@ -9,7 +9,7 @@ import { getAccount } from './utils';

class KubernetesProvider implements Provider {

generateConfig(account: Account): void {}
generateConfig(_account: Account): void {}

exec(account: Account): Environment {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/OPClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync, exec, spawn } from 'child_process';
import {execSync, spawn} from 'node:child_process';

class OPClient {

Expand Down Expand Up @@ -34,8 +34,8 @@ class OPClient {
const sessionTokenLine = signinOutput.trim().split('\n')[0].match(/"(.+?)"/);
const sessionToken = sessionTokenLine ? sessionTokenLine[1] : '';

const tfToken = execSync(`op item get ${this.vault}.TFC_TOKEN --session=${sessionToken} --vault ${this.vault} --format json | jq ".fields[0].value"`).toString().replace(/\"/g, "").trim();
const gitToken = execSync(`op item get ${this.vault}.GIT_TOKEN --session=${sessionToken} --vault ${this.vault} --format json | jq ".fields[0].value"`).toString().replace(/\"/g, "").trim();
const tfToken = execSync(`op item get ${this.vault}.TFC_TOKEN --session=${sessionToken} --vault ${this.vault} --format json | jq ".fields[0].value"`).toString().replaceAll('"', "").trim();
const gitToken = execSync(`op item get ${this.vault}.GIT_TOKEN --session=${sessionToken} --vault ${this.vault} --format json | jq ".fields[0].value"`).toString().replaceAll('"', "").trim();
return {
tfToken,
gitToken
Expand Down
8 changes: 4 additions & 4 deletions src/autocomplete/base.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Command, Config} from '@oclif/core'
import {openSync, writeSync, mkdirSync} from 'fs'
import path from 'path'
import {Command} from '@oclif/core'
import {openSync, writeSync, mkdirSync} from 'node:fs'
import path from 'node:path'

export abstract class AutocompleteBase extends Command {
public get cliBin() {
return this.config.bin
}

public get cliBinEnvVar() {
return this.config.bin.toUpperCase().replace(/-/g, '_')
return this.config.bin.toUpperCase().replaceAll('-', '_')
}

public determineShell(shell: string) {
Expand Down
44 changes: 22 additions & 22 deletions src/autocomplete/powershell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import util from 'util'
import {EOL} from 'os'
import util from 'node:util'
import {EOL} from 'node:os'
import {Config, Interfaces, Command} from '@oclif/core'
import ejs from 'ejs'

Expand Down Expand Up @@ -118,10 +118,12 @@ ${flaghHashtables.join('\n')}
for (const newKey of newKeys) {
childNodes.push(this.genHashtable(newKey, node[key]))
}

childTpl = util.format(childTpl, childNodes.join('\n'))

return util.format(leafTpl, childTpl)
}

// last node
return util.format(leafTpl, childTpl)
}
Expand Down Expand Up @@ -149,7 +151,8 @@ ${flaghHashtables.join('\n')}
)
}
}
if (childNodes.length >= 1) {

if (childNodes.length > 0) {
return util.format(leafTpl, childNodes.join('\n'))
}

Expand All @@ -162,9 +165,10 @@ ${flaghHashtables.join('\n')}
// [System.Management.Automation.CompletionResult] will error out if will error out if you pass in an empty string for the summary.
return ' '
}

return ejs.render(summary, {config: this.config})
.replace(/"/g, '""') // escape double quotes.
.replace(/`/g, '``') // escape backticks.
.replaceAll('"', '""') // escape double quotes.
.replaceAll('`', '``') // escape backticks.
.split(EOL)[0] // only use the first line
}

Expand All @@ -185,16 +189,12 @@ ${flaghHashtables.join('\n')}
) {
nextArgs.push(topicNameSplit[depth])

if (this.coTopics.includes(t.name)) {
node[topicNameSplit[depth]] = {
node[topicNameSplit[depth]] = this.coTopics.includes(t.name) ? {
...genNode(`${partialId}:${topicNameSplit[depth]}`),
}
} else {
node[topicNameSplit[depth]] = {
} : {
_summary: t.description,
...genNode(`${partialId}:${topicNameSplit[depth]}`),
}
}
};
}
}

Expand All @@ -215,6 +215,7 @@ ${flaghHashtables.join('\n')}
}
}
}

return node
}

Expand All @@ -225,16 +226,12 @@ ${flaghHashtables.join('\n')}
// Collect top-level topics and generate a cmd tree node for each one of them.
this.topics.forEach(t => {
if (!t.name.includes(':')) {
if (this.coTopics.includes(t.name)) {
commandTree[t.name] = {
commandTree[t.name] = this.coTopics.includes(t.name) ? {
...genNode(t.name),
}
} else {
commandTree[t.name] = {
} : {
_summary: t.description,
...genNode(t.name),
}
}
};

topLevelArgs.push(t.name)
}
Expand Down Expand Up @@ -404,15 +401,17 @@ Register-ArgumentCompleter -Native -CommandName ${this.config.binAliases ? `@(${
if (a.name < b.name) {
return -1
}

if (a.name > b.name) {
return 1
}

return 0
})
.map(t => {
const description = t.description ?
this.sanitizeSummary(t.description) :
`${t.name.replace(/:/g, ' ')} commands`
`${t.name.replaceAll(':', ' ')} commands`

return {
name: t.name,
Expand All @@ -430,7 +429,7 @@ Register-ArgumentCompleter -Native -CommandName ${this.config.binAliases ? `@(${
p.commands.forEach(c => {
if (c.hidden) return
const summary = this.sanitizeSummary(c.summary || c.description)
const flags = c.flags
const {flags} = c
cmds.push({
id: c.id,
summary,
Expand All @@ -457,9 +456,10 @@ Register-ArgumentCompleter -Native -CommandName ${this.config.binAliases ? `@(${
if (!this.topics.find(t => t.name === topic)) {
this.topics.push({
name: topic,
description: `${topic.replace(/:/g, ' ')} commands`,
description: `${topic.replaceAll(':', ' ')} commands`,
})
}

topic += `:${split[i + 1]}`
}
})
Expand Down
Loading
Loading