git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] parse-options: introduce die_for_required_opt()

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Jun 3, 2026, 11:10 UTC
Message-ID
<20260603111044.39116-2-r.siddharth.shrimali@gmail.com>
In-Reply-To
<20260603111044.39116-1-r.siddharth.shrimali@gmail.com>

Introduce a new helper function die_for_required_opt() to check if a given option is present without its required prerequisite option.

This provides a centralized API for handling simple option dependencies (i.e., X requires Y), matching the style of the existing mutual-exclusion helpers like die_for_incompatible_opt{2,3,4}().

Suggested-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
 parse-options.c | 7 +++++++
 parse-options.h | 3 +++
 2 files changed, 10 insertions(+)
diff --git a/parse-options.c b/parse-options.c
index a676da86f5..e100f9a0c1 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1558,3 +1558,10 @@ void die_for_incompatible_opt4(int opt1, const char *opt1_name,
 		break;
 	}
 }
+
+void die_for_required_opt(int opt1, const char *opt1_name,
+			  int opt2, const char *opt2_name)
+{
+	if (opt1 && !opt2)
+		die(_("the option '%s' requires '%s'"), opt1_name, opt2_name);
+}
diff --git a/parse-options.h b/parse-options.h
index 0d1f738f8d..99dc53325d 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -460,6 +460,9 @@ static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
 				  0, "");
 }
 
+void die_for_required_opt(int opt1, const char *opt1_name,
+			  int opt2, const char *opt2_name);
+
 /*
  * Use these assertions for callbacks that expect to be called with NONEG and
  * NOARG respectively, and do not otherwise handle the "unset" and "arg"
-- 
2.54.0
Previous: Siddharth ShrimaliNext: Jean-Noël AVILA
Message 2 of 10 in “parse-options: introduce die_for_required_opt() helper”
  1. 0/2 parse-options: introduce die_for_required_opt() helperSiddharth Shrimali, Jun 3, 2026
  2. 1/2 parse-options: introduce die_for_required_opt()Siddharth Shrimali, Jun 3, 2026
  3. Jean-Noël AVILAJun 3, 2026
  4. Christian CouderJun 4, 2026
  5. Christian CouderJun 4, 2026
  6. 2/2 builtin/add: use die_for_required_opt() helperSiddharth Shrimali, Jun 3, 2026
  7. Christian CouderJun 4, 2026
  8. Junio C HamanoJun 8, 2026
  9. Christian CouderJun 4, 2026
  10. parse-options: introduce die_for_missing_opt()Siddharth Shrimali, Jun 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.