Skip to content

Commit

Permalink
feat: add config file flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcarman committed May 21, 2024
1 parent a21027c commit 193c6db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions messages/metalint.run.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ You must provide a folder to lint - eg. force-app
# flags.format.summary

Specifies the output format for results.

# flags.config.summary

YAML config file defining rules and settings.
9 changes: 8 additions & 1 deletion src/commands/metalint/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export default class MetalintRun extends SfCommand<MetalintRunResult> {
public static readonly examples = messages.getMessages('examples');

public static readonly flags = {
config: Flags.file({
summary: messages.getMessage('flags.config.summary'),
char: 'c',
required: true,
exists: true,
}),
directory: Flags.directory({
summary: messages.getMessage('flags.directory.summary'),
char: 'd',
Expand All @@ -38,6 +44,7 @@ export default class MetalintRun extends SfCommand<MetalintRunResult> {

public async run(): Promise<MetalintRunResult> {
const { flags } = await this.parse(MetalintRun);
const config = flags['config'];
const dir = flags['directory'];
const format = flags['format'];

Expand All @@ -63,7 +70,7 @@ export default class MetalintRun extends SfCommand<MetalintRunResult> {
results = resultFormatters[format](ruleResults);
this.spinner.stop();

await readConfigFile();
await readConfigFile(config);

this.log(results);

Expand Down
4 changes: 2 additions & 2 deletions src/common/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import yaml from 'js-yaml';
import * as yup from 'yup';
import { ConfigFile } from '../common/types.js';

export async function readConfigFile(): Promise<void> {
const loadedConfig = yaml.load(fs.readFileSync('demo/config.yaml', 'utf8'));
export async function readConfigFile(configFile: string): Promise<void> {
const loadedConfig = yaml.load(fs.readFileSync(configFile, 'utf8'));

const configSchema = yup.object().shape({
version: yup.number().required(),
Expand Down

0 comments on commit 193c6db

Please sign in to comment.