Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# otdfctl Architecture
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS


## Overview

`otdfctl` is a modular, documentation-driven CLI tool. Its architecture ensures that command definitions, arguments, and flags are defined in Markdown documentation files (`docs/man/`). These docs are parsed at runtime to generate CLI help and to drive the registration of command-line arguments and flags, ensuring that code and documentation remain in sync.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS


## Project Structure

- **Commands:**
- Source files for commands are in `cmd/`.
- Each command is registered using `man.Docs.GetCommand`, which loads its definition from the corresponding Markdown doc in `docs/man/`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: Get Command
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- The command string passed to `GetCommand` uses forward slashes (e.g., `dev/hello`, `policy/subject-mappings/update`) to represent the command path.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: Get Command
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- Arguments and flags are registered in code using the doc-driven helpers, e.g.:
```go
cmd.Flags().StringP(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: String, Strings, Stringy, String P
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Name,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Shorthand,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Default,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Description,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

)
```
This ensures the flag's name, shorthand, default, and description are always sourced from the documentation.
- **Handlers:**
- Business logic is implemented in `pkg/handlers/`.
- Command handlers in `cmd/` delegate to these packages for core operations.
- **Configuration:**
- Configuration management is handled in `pkg/config/` and `otdfctl.yaml`.
- **Authentication/Profiles:**
- Authentication flows and user profiles are managed in `pkg/auth/` and `pkg/profiles/`.
- **Documentation:**
- All command and subcommand documentation lives in `docs/man/`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- These Markdown files define command names (with forward slashes), arguments, flags, descriptions, and usage examples.
- The CLI help system is generated from these docs at runtime.
- **TUI:**
- Experimental text-based UI in `tui/`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: too, TUI, took, tool, GUI, tub, tug, DUI, Hui, TDI, TBI, TUC, tai, Tupi, tum, Tut, toot, tut, Tue, tux, AUI, BUI, NUI, OUI, Sui, TAI, TCI, TEI, TGI, TI, TMI, TPI, TRI, TSI, TTI, TU, TUA, TUB, TUG, TUN, TUP, TUV, Tai, Ti, Tu, UI, ti, tun, étui
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- **Testing:**
- End-to-end BATS tests are in `e2e/`.

## Command and Flag Registration Pattern

- The canonical source for command structure, arguments, and flags is the Markdown documentation in `docs/man/`.
- In Go code, commands are registered using `man.Docs.GetCommand("path/to/command", ...)`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: Get Command
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- Flags and arguments are registered using the `GetDocFlag` helper, which pulls all metadata from the doc:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

```go
cmd.Flags().StringP(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: String, Strings, Stringy, String P
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Name,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Shorthand,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Default,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

cmd.GetDocFlag("flagname").Description,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: flag name
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

)
```
- This pattern is used for all commands and subcommands, ensuring that the CLI and its documentation are always in sync.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS


## Adding or Modifying Commands

1. **Write or update the Markdown documentation** for your command in `docs/man/<command>/`. This defines the command's arguments, flags, and help text.
2. **Implement the command handler** in `cmd/`, using `man.Docs.GetCommand` to load the command and inject flags/args from the doc using `GetDocFlag`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: Get Command
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: arms, arts, arcs, Ares, Argos, rags, AGS, Argo, ergs, arks, AGs, ARDS, ARTS, ASGS, Aras, Argus, RGS, ares, argh, xargs
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

3. **Add or update business logic** in `pkg/handlers/` as needed.
4. **Add or update tests** in `e2e/`.
5. **Run and verify** the command, ensuring CLI help matches the documentation.

See `docs/example-add-subcommand.md` for a step-by-step example.

---

Update this document as the architecture evolves.
59 changes: 59 additions & 0 deletions CONTRIBUTOR_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributor Guide: otdfctl
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS


## Project Structure
- **Commands:** Add new commands in `cmd/` using Cobra. Each command should have a corresponding handler in `pkg/handlers/`.
- **Handlers:** Place business logic in `pkg/handlers/`.
- **Configuration:** Use `pkg/config/` and `otdfctl.yaml` for config management.
- **Authentication/Profiles:** Use `pkg/auth/` and `pkg/profiles/` for auth flows and user profiles.
- **Documentation:** Update or add Markdown docs in `docs/man/` for each command. These docs are parsed at runtime for CLI help.
- **TUI:** Experimental; avoid major changes unless contributing to TUI development.
- **Testing:** Add/extend BATS tests in `e2e/` for new features. Use test mode for development.

## How to Add a Command

1. **Create or Update the Command File:**
- For a new top-level command, create a new file in `cmd/` (e.g., `cmd/foo.go`).
- For a subcommand, add it to the appropriate parent command file (e.g., add a `hello` subcommand to `cmd/dev.go`).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- Use the CLI helpers (`cli.New`, `c.Args.GetOptionalString`, `c.Flags.GetOptionalBool`, etc.) for argument and flag parsing, following the style in [`docs/example-add-subcommand.md`](docs/example-add-subcommand.md).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: CLI, clip, CGI, CPI, CSI, CBI, CCI, CLR, CAI, CLP, CLS, CTI, Cali, Clio, CFI, CLT, CNI, cl, CLG, DLI, MLI, Ali, BLI, CDI, CEI, CHI, CI, CII, CL, CLA, CLB, CLC, CLD, CLE, CLH, CLIC, CLIL, CLIS, CLJ, CLL, CLM, CLN, CLQ, CLU, CLV, CLW, CLX, CLY, CLZ, CMI, COI, CQI, CVI, CZI, Chi, Ci, Cl, ELI, Eli, LI, Li, RLI, SLI, chi, clii, clit, clix, clvi, clxi, I, all, can, club, old, call, car, cut, oil, CD, cell, claim, cm, cold, com, fly, FBI, cap, cat, clan, coin, cult, cup, lie, CBC, CDs, CIA, CNN, CPU, LA, UCLA, calm, chip, cliff, climb, clips, ill, lb, ski, slip, CSS, CTV, Clay, Cole, Colin, Lt, PCI, SL, Wei, cab, cf, chin, clad, clay, click, clue, coil, con, cop, cow, cry, cue, flip, lid, lip, CAA, CBA, CBN, CCC, CCD, CDC, CDU, CFB, CIO, CNS, CPA, CPC, CPR, CRT, CSA, CSU, CSX, CV, Cain, Clair, Cliff, Clint, Clive, Colt, DL, GI, GUI, Gil, Kai, Lin, Liz, MRI, Mali, PRI, SCSI, SLR, TLC, UCI, Wii, ale, calf, cam, chili, claw, cod, colt, elf, elk, elm, flu, hi, ml, pi, ply, psi, sci, slid, slim, slit, ACLU, Bali, CAC, CCA, CCP, CCS, CDA, CDR, CEA, CFA, CFC, CFO, CFR, CFS, CIC, CIE, CMA, CME, CMG, CNC, CNG, CNR, CNT, CPP, CRC, CSC, CSF, CSL, CSP, CSR, CST, CTA, CTC, CVS, CWA, Celia, Che, Chin, DCI, DLR, DUI, ELF, Hui, ICL, ILS, KLM, Kali, LD, NLP, OSI, PKI, PPI, RL, SGI, SLA, SLC, TDI, TLS, UCL, UPI, WWI, cal, chic, cilia, clam, clap, clef, cling, clot, col, cola, crib, cub, mil, moi, nil, sly, til, ALU, BLT, CBF, CBM, CBP, CBT, CCG, CCR, CDO, CDT, CEP, CFD, CFE, CFP, CGA, CGS, CKD, CMB, CMF, CMU, CND, CNE, CPE, CPM, CPO, CSD, CSG, CSIS, CSO, CSV, CTF, CTM, CTO, CTP, CVA, CVC, CVR, CVT, Calif, Clem, Cleo, Cline, Colo, DCL, DLA, DLL, DPI, DRI, DTI, Elie, FCI, FDI, FLP, FSI, GDI, GLS, HCl, LCL, LSI, MCL, MDI, MSI, NCI, NLS, NRI, Olin, PMI, RMI, RPI, RSI, SBI, SDI, SLP, SLS, TBI, TLD, Ulm, VLSI, cit, clog, cob, cog, colic, cot, cox, cull, deli, lib, phi, tai, BRI, BWI, CBO, CBR, CCB, CCU, CDN, CFT, CFU, CJC, CJK, CNH, CPF, CRL, CTH, CVD, CWC, DLM, DLS, DWI, Dali, ELT, GLP, HMI, IPI, JCI, JCL, MLF, RCI, SLT, SMI, TLR, Uzi, VLF, blip, chia, chit, coir, coo, coy, cur, ell, glib, ilk, obi, ole, CDV, CIG, COLA, CSH, CTT, CXC, Celt, Cori, FYI, Fri, GMI, HRI, MLD, NLR, SLN, VRI, WLM, alp, cad, clew, clime, clod, coll, cols, cud, flit, lg, ail, caw, clink, coif, cw, ilia, clop, tali, CBS, CDP, CEO, CHG, RBI, chm, cpl, lit, cloy, cpd, liq, AAI, ABI, ACDI, ACI, ACL, ACLs, ADI, AEI, AFI, AGI, AHI, AI, AII, AJI, AL, ALB, ALC, ALD, ALE, ALF, ALG, ALH, ALJ, ALK, ALL, ALM, ALN, ALO, ALP, ALQ, ALR, ALS, ALV, ALW, ALX, ALZ, AMI, ANI, AOI, API, AQI, ARI, ATI, AUI, AVI, AYI, AZI, Abi, Al, Ala, Aldi, BBI, BCI, BCL, BCLH, BDI, BEI, BFI, BGI, BHI, BII, BJI, BKI, BLA, BLB, BLC, BLD, BLE, BLF, BLG, BLL, BLM, BLP, BLR, BLS, BLU, BLV, BLW, BLX, BLY, BLZ, BMI, BNI, BOI, BPI, BSI, BTI, BUI, BVI, BYI, Bi, Blu, C, C&A, C&C, C0G, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C27, C28, C2C, C3, C30, C31, C32, C33, C34, C35, C36, C40, C41, C44, C45, C46, C47, C50, C51, C52, C53, C60, C61, C62, C63, C64, C65, C66, C69, C70, C77, C88, C91, C96, C99, CA, CAB, CAD, CAE, CAF, CAG, CAH, CAJ, CAK, CAL, CALR, CALT, CAM, CAN, CAP, CAQ, CAS, CAT, CAU, CAV, CAW, CAY, CB, CBB, CBCI, CBD, CBE, CBG, CBH, CBIP, CBJ, CBL, CBU, CBV, CBX, CBZ, CC, CCE, CCF, CCH, CCIE, CCIP, CCJ, CCK, CCL, CCM, CCN, CCO, CCQ, CCRI, CCT, CCV, CCW, CCX, CCZ, CCs, CDB, CDD, CDE, CDF, CDG, CDH, CDJ, CDK, CDL, CDM, CDS, CDW, CDZ, CE, CEB, CEC, CED, CEDI, CEE, CEF, CEG, CEJ, CEL, CEM, CEN, CEQ, CER, CES, CESI, CET, CEU, CEV, CF, CFF, CFG, CFH, CFJ, CFL, CFM, CFN, CFPI, CG, CGC, CGE, CGF, CGG, CGH, CGIS, CGJ, CGK, CGL, CGM, CGN, CGO, CGR, CGT, CGU, CGY, CGZ, CH, CHB, CHC, CHD, CHF, CHH, CHK, CHL, CHM, CHN, CHO, CHP, CHQ, CHR, CHS, CHT, CHV, CHW, CHX, CHY, CHZ, CID, CIF, CIH, CIIL, CIJ, CIK, CIL, CILE, CILF, CIM, CIP, CIQ, CIR, CIS, CIT, CIU, CIV, CJ, CJA, CJB, CJF, CJH, CJJ, CJL, CJN, CJS, CK, CKB, CKK, CKM, CKR, CKS, CKY, CKs, CLAH, CLAS, CLSA, CLSC, CLSID, CLTV, CLUF, CM, CMC, CMD, CMJ, CMK, CML, CMLK, CMM, CMO, CMP, CMR, CMS, CMT, CMV, CMW, CMX, CN, CNA, CNB, CNF, CNIL, CNIS, CNJ, CNK, CNL, CNM, CNO, CNP, CNQ, CNU, CNV, CNW, CNX, CNY, CNZ, CO, CO2, CO3, COA, COB, COC, COD, COE, COF, COG, COIN, COK, COL, COM, CON, COP, COQ, COSI, COU, COV, CP, CPD, CPG, CPH, CPIE, CPJ, CPL, CPN, CPQ, CPS, CPT, CPV, CQA, CQC, CQE, CQF, CQG, CQL, CQM, CQP, CQS, CQT, CQX, CQZ, CR, CRA, CRB, CRD, CRE, CRF, CRG, CRH, CRIF, CRIM, CRIQ, CRJ, CRK, CRM, CRN, CRO, CRP, CRQ, CRR, CRS, CRW, CRY, CRZ, CS, CSE, CSIL, CSM, CT, CTB, CTE, CTIF, CTK, CTR, CTs, CUA, CUB, CUC, CUD, CUF, CUG, CUJ, CUL, CUM, CUO, CUP, CUR, CUT, CUU, CUV, CUW, CUZ, CVE, CVF, CVG, CVH, CVL, CVM, CVN, CVO, CVP, CVU, CVV, CVX, CVs, CW, CWB, CWE, CWF, CWL, CWM, CWO, CWP, CWR, CWT, CXE, CXL, CXM, CXO, CXP, CXQ, CXR, CY, CYA, CYK, CYM, CYP, CYT, CYZ, CZ, CZC, CZF, CZJ, CZK, CZL, CZM, CZN, CZO, CZP, CZS, CZT, CZU, CZW, CZX, CZY, CZZ, Ca, Cal, Calo, Can, Cb, Cd, Ce, Cf, Ch, Choi, Chu, Cid, Cm, Co, CoP, Cod, Col, Com, Cox, Coy, Cpl, Cr, Cs, Ct, Cu, Cèlia, Célia, DAI, DCRI, DDI, DEI, DFI, DGI, DHI, DI, DJI, DLC, DLF, DLG, DLH, DLP, DLT, DMI, DNI, DOI, DSI, DVI, DZI, Dalí, Di, EAI, EBI, ECL, EDI, EFI, EI, ELA, ELD, ELN, ELO, ELP, ELQ, ELR, ELS, ELU, EMI, ENI, EOI, EPI, ESI, El, FAI, FCL, FCPI, FEI, FFI, FGI, FI, FII, FJI, FL, FLA, FLB, FLE, FLH, FLIR, FLK, FLL, FLM, FLR, FLS, FLU, FMI, FTI, FWI, Fla, Flo, GCI, GEI, GFI, GHI, GL, GLA, GLM, GLN, GLT, GNI, GOI, GRI, GSI, GTI, HAI, HCI, HCL, HDI, HI, HKI, HL, HLA, HLC, HLM, HLP, HLR, HLS, HOI, IAI, ICI, IFI, IGI, IL, IL2, ILC, ILG, ILM, ILN, ILP, IOI, IRI, ISI, IVI, Ila, Ill, JAI, JLA, JLD, JLM, JLS, JNI, JRI, KCL, KCl, KLB, KLC, KLE, KOI, KPI, L, LBI, LC, LE, LFI, LG, LH, LHI, LIA, LIC, LIH, LIM, LIR, LIX, LL, LLB, LLC, LLD, LLG, LLN, LLP, LLR, LN, LNI, LO, LOI, LP, LPI, LQ, LR, LRI, LS, LT, LTI, LU, LX, LY, La, Le, Lie, Lim, Liu, Liv, Ln, Lr, Lu, M3I, MBI, MCI, MFI, MFi, MGI, MI, ML, MLA, MLB, MLC, MLE, MLIS, MLK, MLM, MLP, MLS, MLT, MLV, MLW, MMI, MOI, MPI, MYI, Mai, NCBI, NCL, NI, NL, NLB, NLD, NLG, NLH, NLO, NLT, NLU, NMI, NNI, NOI, NPI, NTI, NUI, Ni, OAI, OCI, OCL, ODI, OHI, OLA, OLF, OLO, OLP, OLT, OMI, OPI, ORI, OUI, Ola, PBI, PCL, PCSI, PCTI, PDI, PEI, PGI, PHI, PII, PL, PLA, PLB, PLC, PLD, PLE, PLF, PLG, PLH, PLK, PLL, PLM, PLN, PLO, PLP, PLR, PLS, PLT, PLU, PLW, PLX, PNI, POI, PTI, PVI, PWI, PXI, Pei, Pl, QI, Qlik, RAI, RDI, REI, RFI, RI, RKI, RLC, RLD, RLE, RLL, RLS, ROI, RRI, RTI, RVI, SAI, SCI, SCL, SCPI, SFI, SI, SII, SKI, SLB, SLF, SLG, SLIM, SLL, SLO, SLQ, SLSI, SLV, SLZ, SNI, SOI, SPI, SRI, SSI, STI, SVI, Shi, Si, Sri, Sui, TAI, TCI, TCL, TEI, TGI, TI, TL, TLA, TLB, TLE, TLF, TLH, TLM, TLN, TLP, TLT, TLV, TMI, TPI, TRI, TSI, TTI, TUI, Tai, Ti, Tl, UAI, UFI, UGI, UI, UL, ULB, ULC, ULG, ULIP, ULK, ULM, ULR, ULSI, ULT, ULX, UMI, UNI, URI, USI, UTI, VCI, VDI, VEI, VFI, VI, VLA, VLB, VLC, VLE, VLG, VLM, VLN, VMI, VPI, WDI, WI, WLF, WLG, WLT, WLW, WRI, XL, XLG, Xi, YL, Yi, ZI, ZTI, ai, alb, alt, açai, açaí, bi, bl, c, ca, calk, calx, cay, cc, cg, ch, chai, chg, chis, cir, cis, ck, clits, clvii, clxii, clxiv, clxix, clxvi, cmd, co, cor, cos, cps, cs, ct, ctn, ctr, cts, cu, cum, cwt, cx, dpi, fl, flt, i, ii, iii, kl, l, la, lei, lii, lix, ll, lo, ls, lvi, lxi, mCi, mL, mi, oi, ol', pl, plc, plié, pls, poi, ti, ult, uni, vi, vii, vlf, xci, xcii, xcvi, xi, xii, xvi, xxi, CR7, CRLF, CWV, INI, LF, XLS
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Suggestions: Arms, Arts, Arcs, Ares, Argos, AGS, Argo, Ergs, Arks, AGs, ARDS, ARTS, ASGS, Aras, Argus, RGS, Argh, Xargs
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS


2. **Implement Business Logic:**
- Place complex logic in `pkg/handlers/` and call it from your command handler.

3. **Add Documentation:**
- Create or update the Markdown documentation for your command or subcommand in `docs/man/<command>/`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LanguageTool] reported by reviewdog 🐶
Possible spelling mistake found. (MORFOLOGIK_RULE_EN_US)
Rule: https://community.languagetool.org/rule/show/MORFOLOGIK_RULE_EN_US?lang=en-US
Category: TYPOS

- Follow the format shown in the example, including argument and flag descriptions, and usage examples.

4. **Add or Update Tests:**
- Add or extend BATS tests in `e2e/` to cover your new command and its options.

5. **Register the Command:**
- Ensure your command or subcommand is registered with its parent in the `init()` function.

6. **Verify and Sync:**
- Run your command to verify it works as expected.
- Check that CLI help output matches your documentation.

See [`docs/example-add-subcommand.md`](docs/example-add-subcommand.md) for a step-by-step example.

## Documentation-Driven CLI
- The CLI help system is powered by Markdown docs in `docs/man/`.
- Always update docs when adding or changing commands/flags.

## Testing
- Run all BATS tests: `make test-bats`
- Run a specific test: `bats e2e/<test>.bats`
- Use test mode for development: `make build-test`

## TUI Guidelines
- The TUI in `tui/` is experimental. Avoid changes unless coordinated with maintainers.

## Syncing Docs and Code
- When adding or changing commands, always update the corresponding Markdown doc in `docs/man/`.
- Review CLI help output to ensure it matches the documentation.

## Known Limitations
- Some authentication/profile features may not work on all platforms.
- TUI is not production-ready.

---
Update this guide as the project evolves.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The output format (currently `styled` or `json`) is configurable in the `otdfctl
2. Run the handler which is located in `pkg/handlers` and pass the values as arguments
3. Handle any errors and return the result in a lite TUI format

For a detailed example of adding a new subcommand (including arguments, flags, and documentation), see [`docs/example-add-subcommand.md`](docs/example-add-subcommand.md).

### TUI

> [!CAUTION]
Expand All @@ -52,6 +54,17 @@ The TUI will be used to create an interactive experience for the user.
Documentation drives the CLI in this project. This can be found in `/docs/man` and is used in the
CLI via the `man.Docs.GetDoc()` function.

## Documentation-Driven CLI

The CLI help system and usage output are powered by Markdown documentation in `docs/man/`. When adding or changing commands or flags, always update the corresponding Markdown file. The documentation is parsed at runtime and also published to the OpenTDF docs website.

To ensure documentation and code remain in sync:
- Update the relevant Markdown doc in `docs/man/` when you add or change a command.
- Review the CLI help output after changes.
- See `CONTRIBUTOR_GUIDE.md` for more details.

---

## Testing

The CLI is equipped with a test mode that can be enabled by building the CLI with `config.TestMode = true`.
Expand Down
104 changes: 104 additions & 0 deletions docs/example-add-subcommand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Example: Adding a New Subcommand to an Existing Command

This guide demonstrates how to add a `hello` subcommand under the existing `dev` command in `otdfctl`, using the project's CLI helpers and conventions for arguments and flags.

---

## 1. Add Documentation

Create a new file at `docs/man/dev/hello.md` with:

```markdown
---
title: Print Hello, <name>!
command:
name: dev/hello
arguments:
- name: name
description: Name to greet (optional, defaults to 'World')
flags:
- name: excited
description: Print the greeting in uppercase
default: false
---

Prints a greeting to the terminal. If a name is provided, it greets that name. If the `--excited` flag is set, the greeting is printed in uppercase.

### Examples

```
otdfctl dev hello
Hello, World!

otdfctl dev hello Alice
Hello, Alice!

otdfctl dev hello Bob --excited
HELLO, BOB!
```
```

---

## 2. Create the Subcommand in `cmd/dev.go`

Add the following code to `cmd/dev.go`:

```go
// ...existing imports...

var helloCmd = man.Docs.GetCommand("dev/hello", man.WithRun(func(cmd *cobra.Command, args []string) {
c := cli.New(cmd, args)
name := c.Args.GetOptionalString(0, "World")
excited := c.Flags.GetOptionalBool("excited")
msg := fmt.Sprintf("Hello, %s!", name)
if excited {
msg = strings.ToUpper(msg)
}
c.Println(msg)
}))

func init() {
// Register flags using the doc-driven helpers:
helloCmd.Flags().StringP(
helloCmd.GetDocFlag("name").Name,
helloCmd.GetDocFlag("name").Shorthand,
helloCmd.GetDocFlag("name").Default,
helloCmd.GetDocFlag("name").Description,
)
helloCmd.Flags().Bool(
helloCmd.GetDocFlag("excited").Name,
helloCmd.GetDocFlag("excited").DefaultAsBool(),
helloCmd.GetDocFlag("excited").Description,
)
devCmd.AddCommand(helloCmd)
}
```

- **Arguments:** `[name]` (optional) — the name to greet. Defaults to `World` if not provided.
- **Flags:** `--excited` — prints the greeting in uppercase if set.
- **Helpers Used:** `cli.New`, `c.Args.GetOptionalString`, `c.Flags.GetOptionalBool`, `c.Println`, and `GetDocFlag` for doc-driven flag registration.

---

## 3. Test the Subcommand

Run:

```sh
otdfctl dev hello
otdfctl dev hello Alice
otdfctl dev hello Bob --excited
```

You should see:

```
Hello, World!
Hello, Alice!
HELLO, BOB!
```

---

For more complex logic, implement the business logic in `pkg/handlers/` and call it from your subcommand.
Loading