canonical / matter-pi-gpio-commander

Matter Raspberry Pi GPIO Commander - Turn your Pi into a Matter lighting device!
Apache License 2.0
90 stars 3 forks source link

Add support for CLI flags #6

Closed farshidtz closed 1 year ago

farshidtz commented 1 year ago

The application using the C++ takes arguments such as:

Here is the help output of the app:

$ /snap/matter-pi-gpio-commander/current/bin/lighting-app -h
Usage: /snap/matter-pi-gpio-commander/current/bin/lighting-app 

GENERAL OPTIONS

  --ble-device <number>
       The device number for CHIPoBLE, without 'hci' prefix, can be found by hciconfig.

  --wifi
       Enable WiFi management via wpa_supplicant.

  --thread
       Enable Thread management via ot-agent.

  --version <version>
       The version indication provides versioning of the setup payload.

  --vendor-id <id>
       The Vendor ID is assigned by the Connectivity Standards Alliance.

  --product-id <id>
       The Product ID is specified by vendor.

  --custom-flow <Standard = 0 | UserActionRequired = 1 | Custom = 2>
       A 2-bit unsigned enumeration specifying manufacturer-specific custom flow options.

  --capabilities <None = 0, SoftAP = 1 << 0, BLE = 1 << 1, OnNetwork = 1 << 2>
       Discovery Capabilities Bitmask which contains information about Device’s available technologies for device discovery.

  --discriminator <discriminator>
       A 12-bit unsigned integer match the value which a device advertises during commissioning.

  --passcode <passcode>
       A 27-bit unsigned integer, which serves as proof of possession during commissioning. 
       If not provided to compute a verifier, the --spake2p-verifier-base64 must be provided. 

  --spake2p-verifier-base64 <PASE verifier as base64>
       A raw concatenation of 'W0' and 'L' (67 bytes) as base64 to override the verifier
       auto-computed from the passcode, if provided.

  --spake2p-salt-base64 <PASE salt as base64>
       16-32 bytes of salt to use for the PASE verifier, as base64. If omitted, will be generated
       randomly. If a --spake2p-verifier-base64 is passed, it must match against the salt otherwise
       failure will arise.

  --spake2p-iterations <PASE PBKDF iterations>
       Number of PBKDF iterations to use. If omitted, will be 1000. If a --spake2p-verifier-base64 is
       passed, the iteration counts must match that used to generate the verifier otherwise failure will
       arise.

  --secured-device-port <port>
       A 16-bit unsigned integer specifying the listen port to use for secure device messages (default is 5540).

  --secured-commissioner-port <port>
       A 16-bit unsigned integer specifying the listen port to use for secure commissioner messages (default is 5542). Only valid when app is both device and commissioner

  --unsecured-commissioner-port <port>
       A 16-bit unsigned integer specifying the port to use for unsecured commissioner messages (default is 5550).

  --commissioner-fabric-id <fabricid>
       The fabric ID to be used when this device is a commissioner (default in code is 1).

  --command <command-name>
       A name for a command to execute during startup.

  --PICS <filepath>
       A file containing PICS items.

  --KVS <filepath>
       A file to store Key Value Store items.

  --interface-id <interface>
       A interface id to advertise on.

  --trace_file <file>
       Output trace data to the provided file.
  --trace_log <1/0>
       A value of 1 enables traces to go to the log, 0 disables this (default 0).
  --trace_decode <1/0>
       A value of 1 enables traces decoding, 0 disables this (default 0).
  --cert_error_csr_incorrect_type
       Configure the CSRResponse to be built with an invalid CSR type.
  --cert_error_csr_existing_keypair
       Configure the CSRResponse to be built with a CSR where the keypair already exists.
  --cert_error_csr_nonce_incorrect_type
       Configure the CSRResponse to be built with an invalid CSRNonce type.
  --cert_error_csr_nonce_too_long
       Configure the CSRResponse to be built with a CSRNonce that is longer than expected.
  --cert_error_csr_nonce_invalid
       Configure the CSRResponse to be built with a CSRNonce that does not match the CSRNonce from the CSRRequest.
  --cert_error_nocsrelements_too_long
       Configure the CSRResponse to contains an NOCSRElements larger than the allowed RESP_MAX.
  --cert_error_attestation_signature_incorrect_type
       Configure the CSRResponse to be build with an invalid AttestationSignature type.
  --cert_error_attestation_signature_invalid
       Configure the CSRResponse to be build with an AttestationSignature that does not match what is expected.
  --enable-key <key>
       A 16-byte, hex-encoded key, used to validate TestEventTrigger command of Generial Diagnostics cluster

HELP OPTIONS

  -h, --help
       Print this output and then exit.

  -v, --version
       Print the version and then exit..

This PR makes it possible to set the CLI flags for the service.

In addition, it adds a helper app to query the help (CLI usage instructions) by simply running matter-pi-gpio-commander.help instead of the long /snap/matter-pi-gpio-commander/current/bin/lighting-app -h.