Skip to content

feat: add Validator option for additional argument validation - #25

Merged
kazeburo merged 1 commit into
mainfrom
feat/validator-option
Sep 6, 2026
Merged

kazeburo merged 1 commit into
mainfrom
feat/validator-option

Conversation

@kazeburo

@kazeburo kazeburo commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests, Documentation


Description

  • Add post-parse argument validation hook

  • Return UNKNOWN when validation fails

  • Test validator behavior for shipper execution

  • Document validator usage and option


Diagram Walkthrough

flowchart LR
  Parse["Parse command-line arguments"]
  Validate["Run configured validator"]
  Run["Execute Run method"]
  Unknown["Print error and return UNKNOWN"]
  Parse -- "parsed arguments" --> Validate
  Validate -- "validation succeeds" --> Run
  Validate -- "validation fails" --> Unknown
Loading

File Walkthrough

Relevant files
Enhancement
flagrun.go
Add post-parse validator option and execution                       

flagrun.go

  • Add Validator func([]string) error to Flagrun.
  • Add Validator(...) functional option.
  • Invoke validation after successful parsing and required-argument
    checks.
  • Print validation errors and return UNKNOWN.
+15/-0   
Tests
flagrun_shipper_test.go
Test shipper validator failure handling                                   

flagrun_shipper_test.go

  • Add a validation flag and validator method to testShipper.
  • Verify failed validator output returns UNKNOWN.
  • Assert validation errors are written to stderr.
+20/-0   
Documentation
README.md
Document validator option usage and behavior                         

README.md

  • Document flagrun.Validator in Japanese.
  • Add a complete port-validation usage example.
  • Clarify validation timing, error behavior, and supported entry points.
  • Add the option to the configuration table.
+43/-0   
Formatting
go.mod
Reorganize module dependency declarations                               

go.mod

  • Reorganize direct and indirect dependency declarations.
  • Keep existing dependency versions unchanged.
+5/-4     

@sonarqubecloud

sonarqubecloud Bot commented Sep 6, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Broken example

The new example calls os.Exit but does not import os, so users cannot compile it as documented. Add the missing os import.

import (
    "fmt"

    "github.com/monitoring-forge/flagrun"
)

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@kazeburo
kazeburo merged commit 0ef1022 into main Sep 6, 2026
3 checks passed
@kazeburo
kazeburo deleted the feat/validator-option branch September 6, 2026 13:04
@github-actions github-actions Bot mentioned this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant