Skip to content

Commit

Permalink
fix args conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Feb 8, 2024
1 parent 918767b commit 7e876ab
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 118 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ config(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
outputFile?: string
): Promise<string>

fs(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
outputFile?: string
): Promise<string>

repo(
src: Directory | string,
exitCode?: number,
repoUrl?: string,
format?: string,
output?: string
outputFile?: string
): Promise<string>

image(
src: Directory | string,
exitCode?: number,
image?: string,
format?: string,
output?: string
outputFile?: string
): Promise<string>


Expand Down
102 changes: 45 additions & 57 deletions example/.fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@ export const exclude = [".fluentci"];
* @param {Directory | string} src
* @param {number} exitCode
* @param {string} format
* @param {string} output
* @param {string} outputFile
* @returns {Promise<File | string>}
*/
export async function config(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
exitCode = 0,
format = "table",
outputFile?: string
): Promise<File | string> {
const context = await getDirectory(dag, src);
const args = ["config", "."];
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode || "0";
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode;
args.push(`--exit-code=${TRIVY_EXIT_CODE}`);
args.push(`--format=${format}`);

if (format) {
args.push(`--format=${format}`);
}

output = output || "output";
args.push(`--output=${output}`);
outputFile = outputFile || "output";
args.push(`--output=${outputFile}`);

const ctr = dag
.pipeline(Job.config)
Expand All @@ -47,7 +44,7 @@ export async function config(
.withExec(args);

await ctr.stdout();
const id = await ctr.file(`/app/${output}`).id();
const id = await ctr.file(`/app/${outputFile}`).id();
return id;
}

Expand All @@ -57,26 +54,26 @@ export async function config(
* @param {Directory | string} src
* @param {number} exitCode
* @param {string} format
* @param {string} output
* @param {string} outputFile
* @returns {Promise<File | string>}
*/
export async function fs(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
exitCode = 0,
format = "table",
outputFile?: string
): Promise<File | string> {
const context = await getDirectory(dag, src);
const args = ["fs", "."];
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode || "0";
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode;
args.push(`--exit-code=${TRIVY_EXIT_CODE}`);

if (format) {
args.push(`--format=${format}`);
}

output = output || "output";
args.push(`--output=${output}`);
outputFile = outputFile || "output";
args.push(`--output=${outputFile}`);

const ctr = dag
.pipeline(Job.fs)
Expand All @@ -88,7 +85,7 @@ export async function fs(

await ctr.stdout();

const id = await ctr.file(`/app/${output}`).id();
const id = await ctr.file(`/app/${outputFile}`).id();
return id;
}

Expand All @@ -99,27 +96,24 @@ export async function fs(
* @param {number} exitCode
* @param {string} repoUrl
* @param {string} format
* @param {string} output
* @param {string} outputFile
* @returns {Promise<File | string>}
*/
export async function repo(
src: Directory | string,
exitCode?: number,
exitCode = 0,
repoUrl?: string,
format?: string,
output?: string
format = "table",
outputFile?: string
): Promise<File | string> {
const context = await getDirectory(dag, src);
const args = ["repo", Deno.env.get("TRIVY_REPO_URL") || repoUrl || "."];
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode || "0";
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode;
args.push(`--exit-code=${TRIVY_EXIT_CODE}`);
args.push(`--format=${format}`);

if (format) {
args.push(`--format=${format}`);
}

output = output || "output";
args.push(`--output=${output}`);
outputFile = outputFile || "output";
args.push(`--output=${outputFile}`);

const ctr = dag
.pipeline(Job.repo)
Expand All @@ -130,7 +124,7 @@ export async function repo(
.withExec(args);
await ctr.stdout();

const id = await ctr.file(`/app/${output}`).id();
const id = await ctr.file(`/app/${outputFile}`).id();
return id;
}

Expand All @@ -141,15 +135,15 @@ export async function repo(
* @param {number} exitCode
* @param {string} image
* @param {string} format
* @param {string} output
* @param {string} outputFile
* @returns {Promise<File | string>}
*/
export async function image(
src: Directory | string,
exitCode?: number,
exitCode = 0,
image?: string,
format?: string,
output?: string
format = "table",
outputFile?: string
): Promise<File | string> {
const context = await getDirectory(dag, src);
if (!Deno.env.has("TRIVY_IMAGE") && !image) {
Expand All @@ -158,15 +152,12 @@ export async function image(
}

const args = ["image", Deno.env.get("TRIVY_IMAGE") || image!];
args.push(`--format=${format}`);

if (format) {
args.push(`--format=${format}`);
}

output = output || "output";
args.push(`--output=${output}`);
outputFile = outputFile || "output";
args.push(`--output=${outputFile}`);

const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode || "0";
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode;
args.push(`--exit-code=${TRIVY_EXIT_CODE}`);

const ctr = dag
Expand All @@ -178,7 +169,7 @@ export async function image(
.withExec(args);

await ctr.stdout();
const id = await ctr.file(`/app/${output}`).id();
const id = await ctr.file(`/app/${outputFile}`).id();
return id;
}

Expand All @@ -189,15 +180,15 @@ export async function image(
* @param {number} exitCode
* @param {string} path
* @param {string} format
* @param {string} output
* @param {string} outputFile
* @returns {Promise<File | string>}
*/
export async function sbom(
src: Directory | string,
exitCode?: number,
exitCode = 0,
path?: string,
format?: string,
output?: string
format = "table",
outputFile?: string
): Promise<File | string> {
const context = await getDirectory(dag, src);
if (!Deno.env.has("TRIVY_SBOM_PATH") && !path) {
Expand All @@ -206,15 +197,12 @@ export async function sbom(
}

const args = ["sbom", Deno.env.get("TRIVY_SBOM_PATH") || path!];
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode || "0";
const TRIVY_EXIT_CODE = Deno.env.get("TRIVY_EXIT_CODE") || exitCode;
args.push(`--exit-code=${TRIVY_EXIT_CODE}`);
args.push(`--format=${format}`);

if (format) {
args.push(`--format=${format}`);
}

output = output || "output";
args.push(`--output=${output}`);
outputFile = outputFile || "output";
args.push(`--output=${outputFile}`);

const ctr = dag
.pipeline(Job.config)
Expand All @@ -225,7 +213,7 @@ export async function sbom(
.withExec(args);

await ctr.stdout();
const id = await ctr.file(`/app/${output}`).id();
const id = await ctr.file(`/app/${outputFile}`).id();
return id;
}

Expand All @@ -234,7 +222,7 @@ export type JobExec = (
exitCode?: number,
path?: string,
format?: string,
output?: string
outputFile?: string
) => Promise<File | string>;

export const runnableJobs: Record<Job, JobExec> = {
Expand Down
Loading

0 comments on commit 7e876ab

Please sign in to comment.