Skip to content

Commit

Permalink
fix: fix project showing up as undefined (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsalamad authored Nov 17, 2023
1 parent 610fc54 commit 457f3fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/cli/OrganizationsCLIController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export class OrganizationsCLIController extends BaseCLIController {
}
const { code, error, output } = await this.execDvc('organizations get')

if (code === 0) {
if (code !== 0) {
vscode.window.showErrorMessage(
`Retrieving organizations failed: ${error?.message}}`,
)
return {}
} else {
const organizations = JSON.parse(output) as Organization[]
const orgsMap = organizations.reduce((result, currentOrg) => {
result[currentOrg.id] = currentOrg
Expand All @@ -38,11 +43,6 @@ export class OrganizationsCLIController extends BaseCLIController {

StateManager.setWorkspaceState(KEYS.ORGANIZATIONS, orgsMap)
return orgsMap
} else {
vscode.window.showErrorMessage(
`Retrieving organizations failed: ${error?.message}}`,
)
return {}
}
}

Expand Down
38 changes: 23 additions & 15 deletions src/cli/UsagesCLIController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StateManager, KEYS } from '../StateManager'
import { showBusyMessage, hideBusyMessage } from '../components/statusBarItem'
import { BaseCLIController } from './BaseCLIController'
import * as vscode from 'vscode'

export type JSONMatch = {
key: string
Expand Down Expand Up @@ -41,26 +42,33 @@ export class UsagesCLIController extends BaseCLIController {

public async usages(savedFilePath?: string): Promise<JSONMatch[]> {
showBusyMessage('Finding Devcycle code usages')
const { output } = await this.execDvc(
const { code, error, output } = await this.execDvc(
`usages --format=json${
savedFilePath ? ` --include=${savedFilePath}` : ''
}`,
)

const matches = JSON.parse(output) as JSONMatch[]
hideBusyMessage()
const codeUsageKeys = matches.reduce(
(map, match) => {
map[match.key] = true
return map
},
{} as Record<string, boolean>,
)
StateManager.setFolderState(
this.folder.name,
KEYS.CODE_USAGE_KEYS,
codeUsageKeys,
)

if (code !== 0) {
vscode.window.showErrorMessage(
`Error finding code usages: ${error?.message}}`,
)
return []
} else {
const matches = JSON.parse(output) as JSONMatch[]
const codeUsageKeys = matches.reduce(
(map, match) => {
map[match.key] = true
return map
},
{} as Record<string, boolean>,
)
StateManager.setFolderState(
this.folder.name,
KEYS.CODE_USAGE_KEYS,
codeUsageKeys,
)
return matches
}
}
}
2 changes: 1 addition & 1 deletion src/cli/utils/execShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function execShell(cmd: string, cwd: string) {
resolve({
output: out,
error: err,
code: err.code || 0,
code: err.code || 1, // If no error code is provided, return 1 as default code to indicate error
})
}
resolve({
Expand Down

0 comments on commit 457f3fc

Please sign in to comment.