Skip to content

Add link to Ruby options doc in help text #14142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025
Merged
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
2 changes: 2 additions & 0 deletions depend
Original file line number Diff line number Diff line change
Expand Up @@ -14598,6 +14598,7 @@ ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_newline_list.h
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
ruby.$(OBJEXT): $(top_srcdir)/version.h
ruby.$(OBJEXT): {$(VPATH)}assert.h
ruby.$(OBJEXT): {$(VPATH)}atomic.h
ruby.$(OBJEXT): {$(VPATH)}backward/2/assume.h
Expand Down Expand Up @@ -14781,6 +14782,7 @@ ruby.$(OBJEXT): {$(VPATH)}prism/ast.h
ruby.$(OBJEXT): {$(VPATH)}prism/diagnostic.h
ruby.$(OBJEXT): {$(VPATH)}prism/version.h
ruby.$(OBJEXT): {$(VPATH)}prism_compile.h
ruby.$(OBJEXT): {$(VPATH)}revision.h
ruby.$(OBJEXT): {$(VPATH)}ruby.c
ruby.$(OBJEXT): {$(VPATH)}ruby_assert.h
ruby.$(OBJEXT): {$(VPATH)}ruby_atomic.h
Expand Down
7 changes: 7 additions & 0 deletions doc/ruby/options.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<!---
CAUTION

This page on docs.ruby-lang.org is displayed in Ruby's help message (-h and --help).
Please make sure you update the link when renaming or moving this file.
--->

# Ruby Command-Line Options

## About the Examples
Expand Down
6 changes: 5 additions & 1 deletion ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "ruby/util.h"
#include "ruby/version.h"
#include "ruby/internal/error.h"
#include "version.h"

#define singlebit_only_p(x) !((x) & ((x)-1))
STATIC_ASSERT(Qnil_1bit_from_Qfalse, singlebit_only_p(Qnil^Qfalse));
Expand Down Expand Up @@ -403,7 +404,10 @@ usage(const char *name, int help, int highlight, int columns)
unsigned int w = (columns > 80 ? (columns - 79) / 2 : 0) + 16;
#define SHOW(m) show_usage_line(&(m), help, highlight, w, columns)

printf("%sUsage:%s %s [options] [--] [filepath] [arguments]\n", sb, se, name);
printf("%sUsage:%s %s [options] [--] [filepath] [arguments]\n\n", sb, se, name);
printf("Details and examples at https://docs.ruby-lang.org/en/%s/ruby/options_md.html\n",
RUBY_PATCHLEVEL == -1 ? "master" : STRINGIZE(RUBY_VERSION_MAJOR) "." STRINGIZE(RUBY_VERSION_MINOR));

Comment on lines +408 to +410
Copy link
Member

Choose a reason for hiding this comment

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

Detailed info should be only when --help.
And keep revision info only in version.c.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean here.

Detailed info should be only when --help.

We're not showing any detailed info? Just linking to a web page that could explain and give examples about the options in -h and --help. I think it should be shown for both of these cases. Do you have other opinions?

And keep revision info only in version.c.

Do you mean the use of RUBY_PATCHLEVEL? How would we get the information about whether to use master or a version otherwise?

for (i = 0; i < num; ++i)
SHOW(usage_msg[i]);

Expand Down
12 changes: 9 additions & 3 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ def test_source_file

def test_usage
assert_in_out_err(%w(-h)) do |r, e|
assert_operator(r.size, :<=, 25)
longer = r[1..-1].select {|x| x.size >= 80}
assert_operator(r.size, :<=, 26)
longer = r[3..-1].select {|x| x.size >= 80}
assert_equal([], longer)
assert_equal([], e)

version = RUBY_PATCHLEVEL == -1 ? "master" : "#{RUBY_VERSION_MAJOR}.#{RUBY_VERSION_MINOR}"
assert_include(r, "Details and examples at https://docs.ruby-lang.org/en/#{version}/ruby/options_md.html")
end
end

def test_usage_long
assert_in_out_err(%w(--help)) do |r, e|
longer = r[1..-1].select {|x| x.size > 80}
longer = r[3..-1].select {|x| x.size > 80}
assert_equal([], longer)
assert_equal([], e)

version = RUBY_PATCHLEVEL == -1 ? "master" : "#{RUBY_VERSION_MAJOR}.#{RUBY_VERSION_MINOR}"
assert_include(r, "Details and examples at https://docs.ruby-lang.org/en/#{version}/ruby/options_md.html")
end
end

Expand Down
Loading