8000 [FAI-13683] Add new NodeJs airbyte-local CLI: parsing arguments by jeniii · Pull Request #94 · faros-ai/airbyte-local-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[FAI-13683] Add new NodeJs airbyte-local CLI: parsing arguments #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Nov 13, 2024

Conversation

jeniii
Copy link
Collaborator
@jeniii jeniii commented Nov 7, 2024

Description

Provide description here

This only has the parsing and validation part of cli.

The options that are being dropped

  • --src-catalog-overrides <json>
  • --src-catalog-file <path>
  • --src-catalog-json <json>
  • --dst-catalog-file <path>
  • --dst-catalog-json <json>
  • --src-wizard
  • --dst-wizard
  • --dst-stream-prefix <prefix>
  • --max-log-size <size>
  • --max-mem <mem>
  • --max-cpus <cpus>
  • --src-docker-options "<string>
  • --dst-docker-options "<string>
  • --k8s-deployment
  • --k8s-namespace "<string>

The options that are renamed:

  • --check-connection -> --src-check-connection
  • --state <path> -> --state-file <path>
    @cjwooo lmk if you think we shouldn't do any renaming. i just think the new names are more consistent to the rest. or i can keep the old ones as well but have them deprecated

New options

  • --config-file <path>
  • --wizard <src> [dst]: not determined yet. a placeholder for now.

The options stayed

  • --src <image>
  • --dst <image>
  • --src.<key> <value>
  • --dst.<key> <value>
  • --full-refresh
  • --src-output-file <path>
  • --dst-use-host-network
  • --no-src-pull
  • --no-dst-pull
  • --src-only
  • --dst-only <file>
  • --connection-name
  • --keep-containers
  • --log-level
  • --raw-messages
  • --debug

Will address in later PRs

  • wizard option and handling
  • docker options from config file validation and handling
  • documentation for new cli

Example of cli output
Screenshot 2024-11-08 at 12 43 24
Screenshot 2024-11-08 at 12 48 13

Type of change

  • Bug fix
  • New feature
  • Breaking change

@jeniii jeniii marked this pull request as draft November 7, 2024 23:16
@jeniii jeniii marked this pull request as ready for review November 8, 2024 17:53
jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit() was called by commander js');
});
const argv = ['./airbyte-local-cli', 'index.js', '--config-file', 'config-file-path', '--src', 'source-image'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the executable be set up to not require the index.js argument -- i.e. ./airbyte-local-cli --config-file ... --src ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the user runs the exec in terminal, they don't need index.js.

i need this is because i'm mocking the process argv which i think in node js that's how it works. tbh i'm still a bit loose on this nodejs knowledge so i don't know how this exactly works. https://github.com/tj/commander.js/blob/master/typings/index.d.ts#L727

/**
   * Parse `argv`, setting options and invoking commands when defined.
   *
   * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
   *
   * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
   * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
   * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
   * - `'user'`: just user arguments
   *
   * @example
   * ```
   * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
   * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
   * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
   * ```
   *
   * @returns Promise
   */

fullRefresh?: boolean | undefined;
rawMessages?: boolean | undefined;
keepContainers?: boolean | undefined;
logLevel?: string | undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as there's a few options are affecting each other, and we need to merge and src/dst from 3 ways (file | src/dst option | wizard).
the narrowed down one would be only these.

]),
)
.option('--src <image>', 'Airbyte source Docker image')
.option('--dst <image>', 'Airbyte destination Docker image')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't set conflict on src and dst as the other two should be sufficient

.option('--keep-containers', 'Do not remove source and destination containers after they exit')

// Options: Cli settings
.option('--debug', 'Enable debug logging')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will create another ticket to revisit this wording.

return {
...options,
srcImage: options.src,
dstImage: options.dst,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply rename the image to new name.
src/dst being the image flags are kinda a headache and ambiguous to the src.* / dst.* options

}

// Validate the input options
function validateConfigFileInput(config: FarosConfig, inputType: AirbyteConfigInputType) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhh this is kinda ugly. maybe i will think of sth better

// Take the non-default value if provided with `srcOutputFile` option
srcOutputFile: cliOptions.srcOnly ? '/dev/null' : cliOptions.srcOutputFile,
// Rename the `dstOnly` file path to `srcInputFile`
srcInputFile: cliOptions.dstOnly,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or should we rename --dst-only to --src-Input-file? not sure this is a good idea tho


async function main() {
logger.debug('Starting Airbyte Local CLI...');
await parseAndValidateInputs(process.argv);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing in process.argv explicitly for easier testing.
otherwise commander can implicitly parse this as well.

"private": true,
"packageManager": "^npm@10.8.2",
"scripts": {
"version": "node -p \"'export const CLI_VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any better idea on passing the version to the cli?

}
},
"catalog": {},
"dockerOptions": "--memory 2048m --cpus 2"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the example of what the file will looks like. lmk your thoughts

dstUseHostNetwork: cliOptions.dstUseHostNetwork,
// If `dstOnly` is true, do not pull the source image. Otherwise, fall back to option `noSrcPull`
srcPull: cliOptions.dstOnly ? false : cliOptions.srcPull,
dstPull: cliOptions.srcOnly ? false : cliOptions.dstPull,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to do with commander auto parses --no-src-pull to srcPull instead of noSrcPull.

@jeniii
Copy link
Collaborator Author
jeniii commented Nov 8, 2024

78.9% :((

export interface FarosConfig {
src?: AirbtyeConfig;
dst?: AirbtyeConfig;
srcOutputFile: string | undefined; // if srcOnly is true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do <name>?: <type> instead of <name>: <type> | undefined for all these properties just like you did for src and dst

Copy link
Collaborator Author
@jeniii jeniii Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow the type complains. but i will look into why

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that as the optional fields are from CliOptions, they turned to string | undefined in FarosConfig.
Screenshot 2024-11-13 at 10 08 57
it seems like I will have to do additional checking to avoid the type complaining which i think it's probably not worth it.... :))))) correct me if i'm wrong

I gave all the boolean type fields default values, which i think probably is a better idea anyway.
but keep the string type fields the same.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
79.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@jeniii
Copy link
Collaborator Author
jeniii commented Nov 13, 2024

79.9%??? ohhhh :((

@jeniii jeniii merged commit 1f04bb3 into main Nov 13, 2024
2 of 3 checks passed
@jeniii jeniii deleted the jg/ts-cli-init branch November 13, 2024 18:24
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0