Skip to content

Commit

Permalink
feat: Simplify CLI args by removing configDir
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Jun 12, 2024
1 parent 86e6602 commit 53f3f22
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ git clone https://github.com/netwerk-digitaal-erfgoed/ld-workbench.git
cd ld-workbench
npm i
npm run compile
npm run ld-workbench -- --configDir static/example
npm run ld-workbench -- --config static/example
```

The configuration of this project is validated and defined by [JSON Schema](https://json-schema.org). The schema is located in `./static/ld-workbench-schema.json`. To create the types from this schema, run `npm run util:json-schema-to-typescript`. This will regenerate `./src/types/LDWorkbenchConfiguration.d.ts`, do not modify this file by hand.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"prepare": "husky install",
"dev": "tsc --watch --preserveWatchOutput",
"ld-workbench": "node build/main",
"ld-workbench:example": "node build/main --configDir static",
"ld-workbench:example": "node build/main --config static",
"util:json-schema-to-typescript": "npx json2ts -i ./static/ld-workbench.schema.json -o src/lib/LDWorkbenchConfiguration.d.ts",
"semantic-release": "semantic-release",
"lint": "gts lint",
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"pretest": "npm run compile",
"posttest": "npm run lint"
"posttest": "npm run fix"
},
"repository": {
"type": "git",
Expand Down
37 changes: 5 additions & 32 deletions src/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ program
.name('ld-workbench')
.description('CLI tool to transform Linked Data using SPARQL')
.option(
'-c, --config <config.yml>',
'Path to a configuration file for your pipeline.'
)
.option(
'--configDir </path/to/yaml/>',
'Path to a folder containing your configuration files.'
'-c, --config </path/to/configurations/>',
'Path to the directory containing your pipeline configuration(s)',
'pipelines/'
)
.option(
'-p, --pipeline <name-of-pipeline>',
Expand All @@ -26,13 +23,12 @@ program
.option('--init', 'Initializes a new LDWorkbench project')
.option(
'--silent',
'Disable console output, including the progress indicator.'
'Disable console output, including the progress indicator'
)
.version(version());
program.parse();
export const cliArgs: {
config?: string;
configDir?: string;
config: string;
pipeline?: string;
stage?: string;
silent?: boolean;
Expand All @@ -56,26 +52,3 @@ if (cliArgs.init !== undefined) {
error(e as Error);
}
}

if (cliArgs.config !== undefined && cliArgs.configDir !== undefined) {
error(
'Do not use both the --config and the --configDir options.',
1,
`${chalk.italic(
'--config'
)} should be used to process a single pipeline, ${chalk.italic(
'--configDir'
)} should be used to overwrite the default director where LD Workbench searches configs (${chalk.italic(
'./pipelines/'
)}).`
);
}
if (cliArgs.config !== undefined && cliArgs.pipeline !== undefined) {
error(
'Do not use both the --config and the --pipeline options.',
1,
`Both ${chalk.italic('--config')} and ${chalk.italic(
'--pipeline'
)} should be used to process a single pipeline.`
);
}
23 changes: 5 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@ console.info(
);

async function main(): Promise<void> {
let pipelines = new Map<string, LDWorkbenchConfiguration>();
pipelines = loadPipelines(
cliArgs.config ?? cliArgs.configDir ?? './pipelines/'
);

const names = Array.from(pipelines.keys());

// this will be the configuration we use:
const pipelines = loadPipelines(cliArgs.config ?? './pipelines/');
const names = [...pipelines.keys()];
let configuration: LDWorkbenchConfiguration | undefined;

if (cliArgs.pipeline !== undefined) {
const config = pipelines.get(cliArgs.pipeline);
if (config === undefined) {
configuration = pipelines.get(cliArgs.pipeline);
if (configuration === undefined) {
error(
`No pipeline named "${cliArgs.pipeline}" was found.`,
`No pipeline named ${cliArgs.pipeline} was found.`,
2,
`Valid pipeline names are: ${names.map(name => `"${name}"`).join(', ')}`
);
}
configuration = pipelines.get(cliArgs.pipeline);
} else if (names.length === 1) {
configuration = pipelines.get(names[0]);
}
Expand All @@ -54,12 +47,6 @@ async function main(): Promise<void> {
);
}
configuration = pipelines.get(answers.pipeline);
} else if (names.length !== 1) {
error(
'This should not happen: no pipeline was picked, but we have multiple.'
);
} else {
configuration = pipelines.get(names[0]);
}

if (configuration === undefined) {
Expand Down

0 comments on commit 53f3f22

Please sign in to comment.