Skip to content

Commit 46f2061

Browse files
committed
Set a custom usage syntax for string and string-array options
1 parent fdaf6a3 commit 46f2061

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

src/main/java/org/truffleruby/options/Options.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class Options {
2828
public final String[] LOAD_PATHS;
2929
/** --required-libraries=StringArrayOptionType.EMPTY_STRING_ARRAY */
3030
public final String[] REQUIRED_LIBRARIES;
31-
/** --working-directory="" */
31+
/** --working-directory="." */
3232
public final String WORKING_DIRECTORY;
3333
/** --debug=false */
3434
public final boolean DEBUG;
3535
/** --verbose=Verbosity.FALSE */
3636
public final Verbosity VERBOSITY;
37-
/** --source-encoding="" */
37+
/** --source-encoding="UTF-8" */
3838
public final String SOURCE_ENCODING;
3939
/** --internal-encoding="" */
4040
public final String INTERNAL_ENCODING;

src/main/ruby/truffleruby/post-boot/post-boot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
Truffle::Boot.delay do
7070
wd = Truffle::Boot.get_option('working-directory')
71-
Dir.chdir(wd) unless wd.empty?
71+
Dir.chdir(wd) unless wd.empty? || wd == '.'
7272
end
7373

7474
if Truffle::Boot.ruby_home

src/options.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ LANGUAGE_OPTIONS:
5555
USER:
5656
STABLE:
5757
# Options corresponding to MRI options, which are also useful outside the TruffleRuby launcher
58-
LOAD_PATHS: [[load-paths, -I], string-array, [], Load paths]
59-
REQUIRED_LIBRARIES: [[required-libraries, -r], string-array, [], Required libraries]
60-
WORKING_DIRECTORY: [[working-directory, -C], string, '', Interpreter will switch to this directory]
58+
LOAD_PATHS: [[load-paths, -I], string-array, '<path>,<path>,...', Load paths]
59+
REQUIRED_LIBRARIES: [[required-libraries, -r], string-array, '<path>,<path>,...', Required libraries]
60+
WORKING_DIRECTORY: [[working-directory, -C], string, '.', Interpreter will switch to this directory]
6161
DEBUG: [[debug, -d], boolean, false, 'Sets $DEBUG to this value']
6262
VERBOSITY: [[verbose, -v, -w, -W], enum/verbosity, false, 'Sets $VERBOSE to this value']
63-
SOURCE_ENCODING: [[source-encoding, -K], string, '', Source encoding]
64-
INTERNAL_ENCODING: [[internal-encoding, -E, -U], string, '', Internal encoding]
65-
EXTERNAL_ENCODING: [[external-encoding, -E], string, '', External encoding]
63+
SOURCE_ENCODING: [[source-encoding, -K], string, 'UTF-8', Source encoding]
64+
INTERNAL_ENCODING: [[internal-encoding, -E, -U], string, ['', '<nil>'], Internal encoding]
65+
EXTERNAL_ENCODING: [[external-encoding, -E], string, ['', '<locale>'], External encoding]
6666
BACKTRACE_LIMIT: [[backtrace-limit], integer, -1, limit the maximum length of backtrace displayed]
6767

6868
EXPERT:
6969
EXPERIMENTAL:
7070
# Setting home and launcher, useful for embedding
7171
NO_HOME_PROVIDED: [no-home-provided, boolean, false, set to true to explicitly state that no home is provided (silences the warnings)]
72-
LAUNCHER: [launcher, string, '', The location of the TruffleRuby launcher program]
73-
CORE_LOAD_PATH: [core-load-path, string, 'resource:/truffleruby', Location to load the Truffle core library from]
72+
LAUNCHER: [launcher, string, ['', '<set by launcher>'], The location of the TruffleRuby launcher program]
73+
CORE_LOAD_PATH: [core-load-path, string, ['resource:/truffleruby', '<path, default is from cache>'], Location to load the Truffle core library from]
7474

7575
# CRuby features (--enable/disable-FEATURE), also exposed as options so they can be used outside the Ruby launcher
7676
FROZEN_STRING_LITERALS: [frozen-string-literals, boolean, false, Use frozen string literals]
@@ -161,8 +161,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
161161
SYNTAX_CHECK: [[syntax-check, -c], boolean, false, Do not execute just check syntax]
162162

163163
# Used internally for the launcher to communicate with the RubyContext
164-
ARGV_GLOBAL_VALUES: [argv-global-values, string-array, [], Parsed options from script argv with a value]
165-
ARGV_GLOBAL_FLAGS: [argv-global-flags, string-array, [], Parsed options from script argv acting as flags (no value)]
164+
ARGV_GLOBAL_VALUES: [argv-global-values, string-array, '<key>,<value>,...', Parsed options from script argv with a value]
165+
ARGV_GLOBAL_FLAGS: [argv-global-flags, string-array, '<flag>,<flag>,...', Parsed options from script argv acting as flags (no value)]
166166
BUILDING_CORE_CEXTS: [building-core-cexts, boolean, false, 'Used while building TruffleRuby to build core C extensions']
167167

168168
# Low-level logging of implementation details

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public class OptionsCatalog {
2222

2323
public static final OptionKey<String[]> LOAD_PATHS_KEY = new OptionKey<>(StringArrayOptionType.EMPTY_STRING_ARRAY, StringArrayOptionType.INSTANCE);
2424
public static final OptionKey<String[]> REQUIRED_LIBRARIES_KEY = new OptionKey<>(StringArrayOptionType.EMPTY_STRING_ARRAY, StringArrayOptionType.INSTANCE);
25-
public static final OptionKey<String> WORKING_DIRECTORY_KEY = new OptionKey<>("");
25+
public static final OptionKey<String> WORKING_DIRECTORY_KEY = new OptionKey<>(".");
2626
public static final OptionKey<Boolean> DEBUG_KEY = new OptionKey<>(false);
2727
public static final OptionKey<Verbosity> VERBOSITY_KEY = new OptionKey<>(Verbosity.FALSE);
28-
public static final OptionKey<String> SOURCE_ENCODING_KEY = new OptionKey<>("");
28+
public static final OptionKey<String> SOURCE_ENCODING_KEY = new OptionKey<>("UTF-8");
2929
public static final OptionKey<String> INTERNAL_ENCODING_KEY = new OptionKey<>("");
3030
public static final OptionKey<String> EXTERNAL_ENCODING_KEY = new OptionKey<>("");
3131
public static final OptionKey<Integer> BACKTRACE_LIMIT_KEY = new OptionKey<>(-1);
@@ -184,7 +184,7 @@ public class OptionsCatalog {
184184
.help("Interpreter will switch to this directory (configured by the -C Ruby option)")
185185
.category(OptionCategory.USER)
186186
.stability(OptionStability.STABLE)
187-
.usageSyntax("\"\"")
187+
.usageSyntax(".")
188188
.build();
189189

190190
public static final OptionDescriptor DEBUG = OptionDescriptor
@@ -208,23 +208,23 @@ public class OptionsCatalog {
208208
.help("Source encoding (configured by the -K Ruby option)")
209209
.category(OptionCategory.USER)
210210
.stability(OptionStability.STABLE)
211-
.usageSyntax("\"\"")
211+
.usageSyntax("UTF-8")
212212
.build();
213213

214214
public static final OptionDescriptor INTERNAL_ENCODING = OptionDescriptor
215215
.newBuilder(INTERNAL_ENCODING_KEY, "ruby.internal-encoding")
216216
.help("Internal encoding (configured by the -E, -U Ruby options)")
217217
.category(OptionCategory.USER)
218218
.stability(OptionStability.STABLE)
219-
.usageSyntax("\"\"")
219+
.usageSyntax("<nil>")
220220
.build();
221221

222222
public static final OptionDescriptor EXTERNAL_ENCODING = OptionDescriptor
223223
.newBuilder(EXTERNAL_ENCODING_KEY, "ruby.external-encoding")
224224
.help("External encoding (configured by the -E Ruby option)")
225225
.category(OptionCategory.USER)
226226
.stability(OptionStability.STABLE)
227-
.usageSyntax("\"\"")
227+
.usageSyntax("<locale>")
228228
.build();
229229

230230
public static final OptionDescriptor BACKTRACE_LIMIT = OptionDescriptor
@@ -248,15 +248,15 @@ public class OptionsCatalog {
248248
.help("The location of the TruffleRuby launcher program")
249249
.category(OptionCategory.EXPERT)
250250
.stability(OptionStability.EXPERIMENTAL)
251-
.usageSyntax("\"\"")
251+
.usageSyntax("<set by launcher>")
252252
.build();
253253

254254
public static final OptionDescriptor CORE_LOAD_PATH = OptionDescriptor
255255
.newBuilder(CORE_LOAD_PATH_KEY, "ruby.core-load-path")
256256
.help("Location to load the Truffle core library from")
257257
.category(OptionCategory.EXPERT)
258258
.stability(OptionStability.EXPERIMENTAL)
259-
.usageSyntax("\"resource:/truffleruby\"")
259+
.usageSyntax("<path, default is from cache>")
260260
.build();
261261

262262
public static final OptionDescriptor FROZEN_STRING_LITERALS = OptionDescriptor
@@ -752,15 +752,15 @@ public class OptionsCatalog {
752752
.help("Parsed options from script argv with a value")
753753
.category(OptionCategory.INTERNAL)
754754
.stability(OptionStability.EXPERIMENTAL)
755-
.usageSyntax("<path>,<path>,...")
755+
.usageSyntax("<key>,<value>,...")
756756
.build();
757757

758758
public static final OptionDescriptor ARGV_GLOBAL_FLAGS = OptionDescriptor
759759
.newBuilder(ARGV_GLOBAL_FLAGS_KEY, "ruby.argv-global-flags")
760760
.help("Parsed options from script argv acting as flags (no value)")
761761
.category(OptionCategory.INTERNAL)
762762
.stability(OptionStability.EXPERIMENTAL)
763-
.usageSyntax("<path>,<path>,...")
763+
.usageSyntax("<flag>,<flag>,...")
764764
.build();
765765

766766
public static final OptionDescriptor BUILDING_CORE_CEXTS = OptionDescriptor

tool/generate-options.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ def parse_reference_defaults(default)
7373
when 'string'
7474
type = 'String'
7575
boxed_type = type
76-
default = default.nil? ? 'null' : "\"#{default.to_s}\""
77-
usage_syntax = generate_usage_syntax[default]
76+
if default.is_a?(Array)
77+
default, usage_syntax = default
78+
else
79+
usage_syntax = generate_usage_syntax[default]
80+
end
81+
default = default.inspect
7882
when 'string-array'
79-
raise unless default.empty?
83+
raise unless default.end_with?(',...')
8084
type = 'String[]'
8185
boxed_type = type
86+
usage_syntax = default
8287
default = "StringArrayOptionType.EMPTY_STRING_ARRAY"
8388
option_type = 'StringArrayOptionType.INSTANCE'
84-
usage_syntax = '<path>,<path>,...'
8589
else
8690
raise type.to_s
8791
end

0 commit comments

Comments
 (0)