cncf-tags / container-device-interface-rs

Rust implementation of the Container Device Interface: https://github.com/cncf-tags/container-device-interface
Apache License 2.0
5 stars 6 forks source link

add or refactir cdi bin or validate bin #9

Closed Apokleos closed 5 months ago

Apokleos commented 5 months ago

cdi: add initalized cdi binary implementation

It's the first part of cdi bin implementation focusing on the framework building with clap.

validate: refactor the initalized validate implementation

Do refactor the inital implementation of validate and align its implementation with the approach used in the cdi bin.

Signed-off-by: Alex Lyn alex.lyn@antgroup.com

Apokleos commented 5 months ago

Hi Zvonko @zvonkok PTAL, Thx !

Apokleos commented 5 months ago

With the ctl cdi we can get help info as below:

$target/debug/cdi -h
Usage: cdi <COMMAND>

Commands:
  devices  List devices in the CDI registry.
  inject   Inject CDI devices into an OCI Spec.
  help     Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help (see more with '--help')
  -V, --version  Print version

[alex.lyn@devel01 /root/cdi-public-rs]
$target/debug/cdi --help
The 'cdi' utility allows you to inspect and interact with the
CDI Registry. Various commands are available for listing CDI
Spec files, vendors, classes, devices, validating the content
of the registry, injecting devices into OCI Specs, and for
monitoring changes in the Registry.

See cdi --help for a list of available commands. You can get
additional help about <command> by using 'cdi <command> -h'.

Usage: cdi <COMMAND>

Commands:
  devices  List devices in the CDI registry.
  inject   Inject CDI devices into an OCI Spec.
  help     Print this message or the help of the given subcommand(s)

Options:
  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

[alex.lyn@devel01 /root/cdi-public-rs]
$target/debug/cdi inject -h
Inject CDI devices into an OCI Spec.

Usage: cdi inject [OPTIONS] <OCI_SPEC> <CDI_DEVICES>...

Arguments:
  <OCI_SPEC>        OCI Spec File
  <CDI_DEVICES>...  CDI Device List

Options:
  -o, --output <FORMAT>  output format for OCI Spec (json|yaml) [default: " "]
  -h, --help             Print help (see more with '--help')
  -V, --version          Print version

[alex.lyn@devel01 /root/cdi-public-rs]
$target/debug/cdi inject --help
The 'inject' command reads an OCI Spec from a file (use "-" for stdin),
injects a requested set of CDI devices into it and dumps the resulting
updated OCI Spec.

Usage: cdi inject [OPTIONS] <OCI_SPEC> <CDI_DEVICES>...

Arguments:
  <OCI_SPEC>
          OCI Spec File

  <CDI_DEVICES>...
          CDI Device List

Options:
  -o, --output <FORMAT>
          output format for OCI Spec (json|yaml)

          [default: " "]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

with ctl validate we can get help info as below:

[alex.lyn@devel01 /root/cdi-public-rs]
$target/debug/validate --help
Validate is used to check document with specified schema.
You can use validate in following ways:

1.specify document file as an argument
  validate --schema <schema.json> <document.json>

2.pass document content through a pipe
  cat <document.json> | validate --schema <schema.json>

3.input document content manually, ended with ctrl+d(or your self-defined EOF keys)
  validate --schema <schema.json>
  [INPUT DOCUMENT CONTENT HERE]     

Usage: validate [OPTIONS] [document]

Arguments:
  [document]
          Document to be validated (default "-") and it's regarded as index argument

          [default: -]

Options:
      --schema <SCHEMA>
          JSON Schema to validate against (default "builtin")

          [default: builtin]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

[alex.lyn@devel01 /root/cdi-public-rs]
$target/debug/validate -h
validate cli

Usage: validate [OPTIONS] [document]

Arguments:
  [document]  Document to be validated (default "-") and it's regarded as index argument [default: -]

Options:
      --schema <SCHEMA>  JSON Schema to validate against (default "builtin") [default: builtin]
  -h, --help             Print help (see more with '--help')
  -V, --version          Print version
zvonkok commented 5 months ago

Thank you for your great work!!