forked from systeminit/si
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using named arguments to handle better arg parsing in API test …
…deno app
- Loading branch information
1 parent
d176857
commit 9c15431
Showing
9 changed files
with
201 additions
and
66 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
export function parseArgs(args: string[]) { | ||
// Parse arguments using std/flags | ||
const parsedArgs = parse(args, { | ||
string: ["workspaceId", "userId", "password", "profile", "tests"], | ||
alias: { w: "workspaceId", u: "userId", p: "password", t: "tests", l: "profile" }, | ||
default: { profile: undefined, tests: "" }, | ||
boolean: ["help"], | ||
}); | ||
|
||
// Display help information if required arguments are missing or help flag is set | ||
if (parsedArgs.help || !parsedArgs.workspaceId || !parsedArgs.userId) { | ||
console.log(` | ||
Usage: deno run main.ts [options] | ||
Options: | ||
--workspaceId, -w Workspace ID (required) | ||
--userId, -u User ID (required) | ||
--password, -p User password (optional) | ||
--tests, -t Test names to run (comma-separated, optional) | ||
--profile, -l Test profile in JSON format (optional) | ||
--help Show this help message | ||
`); | ||
Deno.exit(0); | ||
} | ||
|
||
// Extract parsed arguments | ||
const workspaceId = parsedArgs.workspaceId; | ||
const userId = parsedArgs.userId; | ||
const password = parsedArgs.password || undefined; | ||
|
||
// Handle optional tests argument | ||
const testsToRun = parsedArgs.tests ? parsedArgs.tests.split(",").map(test => test.trim()).filter(test => test) : []; | ||
|
||
// Parse profile JSON if provided, otherwise the profile is one shot [aka single execution] | ||
let testProfile = "one-shot"; | ||
if (parsedArgs.profile) { | ||
try { | ||
testProfile = JSON.parse(parsedArgs.profile); | ||
} catch (error) { | ||
throw new Error(`Failed to parse profile JSON: ${error.message}`); | ||
} | ||
} | ||
|
||
return { workspaceId, userId, password, testsToRun, testProfile }; | ||
} | ||
|
||
export function checkEnvironmentVariables(env: Record<string, string | undefined>) { | ||
const requiredVars = ["SDF_API_URL", "AUTH_API_URL"]; | ||
const missingVars = requiredVars.filter(varName => !env[varName] || env[varName]?.length === 0); | ||
|
||
if (missingVars.length > 0) { | ||
throw new Error(`Missing environment variables: ${missingVars.join(", ")}`); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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