Skip to content

Add CLI option to create a command validator via cli_generator#2467

Merged
mcosgriff merged 3 commits intomainfrom
CLI-option-to-create-a-command-validator-via-cli_generator
Oct 22, 2025
Merged

Add CLI option to create a command validator via cli_generator#2467
mcosgriff merged 3 commits intomainfrom
CLI-option-to-create-a-command-validator-via-cli_generator

Conversation

@mcosgriff
Copy link
Copy Markdown
Contributor

  • Updated openc3 command completion
  • Added option to openc3 cli to generate a command validator

Closes #2394

@mcosgriff
Copy link
Copy Markdown
Contributor Author

image

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.64%. Comparing base (5a581cd) to head (1ccd30f).
⚠️ Report is 41 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2467      +/-   ##
==========================================
+ Coverage   79.55%   79.64%   +0.09%     
==========================================
  Files         658      658              
  Lines       50377    50419      +42     
  Branches      736      736              
==========================================
+ Hits        40075    40157      +82     
+ Misses      10222    10182      -40     
  Partials       80       80              
Flag Coverage Δ
python 81.65% <ø> (-0.04%) ⬇️
ruby-api 84.57% <ø> (ø)
ruby-backend 82.96% <ø> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcosgriff
Copy link
Copy Markdown
Contributor Author

image

@mcosgriff mcosgriff requested a review from jmthomas October 20, 2025 17:20
@mcosgriff
Copy link
Copy Markdown
Contributor Author

Will update the documentation in #2215

@mcosgriff
Copy link
Copy Markdown
Contributor Author

from openc3.packets.command_validator import CommandValidator
# Using the OpenC3 API requires the following imports:
# from openc3.api import wait_check

# Custom command validator class
# See https://docs.openc3.com/docs/configuration/command
class DoubleCommandValidator(CommandValidator):
    def __init__(self, *args):
        super().__init__()
        self.args = args

    # Called before a command is sent
    # @param command [dict] The command dictionary containing all the command details
    # @return [list] First element is True/False/None for success/failure/unknown,
    #   second element is an optional message string
    def pre_check(self, command):
        # Add your pre-command validation logic here
        # Example:
        # target_name = command['target_name']
        # command_name = command['cmd_name']
        # params = command['cmd_params']
        #
        # if some_condition:
        #     return [False, "Command validation failed: reason"]

        # Return True to indicate Success, False to indicate Failure,
        # and None to indicate Unknown. The second value is the optional message.
        return [True, None]

    # Called after a command is sent
    # @param command [dict] The command dictionary containing all the command details
    # @return [list] First element is True/False/None for success/failure/unknown,
    #   second element is an optional message string
    def post_check(self, command):
        # Add your post-command validation logic here
        # Example:
        # Use the OpenC3 API to check telemetry or wait for responses
        # wait_check("TARGET PACKET ITEM == 'EXPECTED'", 5) # Wait up to 5 seconds
        #
        # if some_condition:
        #     return [False, "Post-command validation failed: reason"]

        # Return True to indicate Success, False to indicate Failure,
        # and None to indicate Unknown. The second value is the optional message.
        return [True, None]

@mcosgriff mcosgriff merged commit d4cb228 into main Oct 22, 2025
29 of 30 checks passed
@mcosgriff mcosgriff deleted the CLI-option-to-create-a-command-validator-via-cli_generator branch October 22, 2025 22:09
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command validator failing with RuntimeError('Token is nil')

2 participants