-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
871f7f2
commit 9661d6b
Showing
2 changed files
with
48 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
import { Command, flags } from '@oclif/command'; | ||
import { createRootContainer } from '../inversify.config'; | ||
import { Scanner } from '../scanner'; | ||
import { PracticeImpact } from '../model'; | ||
|
||
export default class Practices extends Command { | ||
static description = 'describe the command here'; | ||
static description = 'List all practices id with name and impact'; | ||
|
||
static examples = [ | ||
`$ example-multi-ts hello | ||
hello world from ./src/hello.ts! | ||
`, | ||
]; | ||
static examples = [`$ dx-scanner practices`]; | ||
|
||
static flags = { | ||
help: flags.help({ char: 'h' }), | ||
// flag with a value (-n, --name=VALUE) | ||
name: flags.string({ char: 'n', description: 'name to print' }), | ||
// flag with no value (-f, --force) | ||
force: flags.boolean({ char: 'f' }), | ||
json: flags.boolean({ char: 'j', description: 'Print practices in JSON' }), | ||
}; | ||
|
||
static args = [{ name: 'path', default: process.cwd() }]; | ||
|
||
async run() { | ||
const { args, flags } = this.parse(Practices); | ||
|
||
const name = flags.name || 'world'; | ||
this.log(`This is name: ${name} `); | ||
this.log(`Log all practices`); | ||
// if (args.file && flags.force) { | ||
// this.log(`you input --force and --file: ${args.file}`); | ||
// } | ||
const scanPath = args.path; | ||
const json = flags.json; | ||
|
||
const container = createRootContainer({ | ||
uri: scanPath, | ||
auth: undefined, | ||
json, | ||
ci: false, | ||
}); | ||
const scanner = container.get(Scanner); | ||
|
||
const practices = await scanner.getPractices(); | ||
const practicesToReport: PracticeToReport[] = []; | ||
practices.forEach((practice) => { | ||
const practiceId: string = practice.getMetadata().id; | ||
practicesToReport.push({ | ||
[practiceId]: { name: practice.getMetadata().name, impact: practice.getMetadata().impact }, | ||
}); | ||
}); | ||
if (flags.json) { | ||
// print practices in JSON format | ||
console.log(JSON.stringify(practicesToReport, null, 2)); | ||
} else { | ||
console.log(practicesToReport); | ||
} | ||
process.exit(0); | ||
} | ||
} | ||
|
||
interface PracticeToReport { | ||
[id: string]: { | ||
name: string; | ||
impact: PracticeImpact; | ||
}; | ||
} |