[前][次][番号順一覧][スレッド一覧]

ruby-changes:55666

From: Nobuyoshi <ko1@a...>
Date: Mon, 6 May 2019 15:31:07 +0900 (JST)
Subject: [ruby-changes:55666] Nobuyoshi Nakada: 7e72ce0f73 (trunk): Load OptionParser defaults from XDG and Haiku standards

https://git.ruby-lang.org/ruby.git/commit/?id=7e72ce0f73

From 7e72ce0f734113e3e215a74b440092443e957d45 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 6 May 2019 15:30:44 +0900
Subject: Load OptionParser defaults from XDG and Haiku standards


diff --git a/lib/optparse.rb b/lib/optparse.rb
index 5cdcabf..9937e25 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1806,13 +1806,26 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1806
   # is not present. Returns whether successfully loaded.
   #
   # +filename+ defaults to basename of the program without suffix in a
-  # directory ~/.options.
+  # directory ~/.options, then the basename with '.options' suffix
+  # under XDG and Haiku standard places.
   #
   def load(filename = nil)
-    begin
-      filename ||= File.expand_path(File.basename($0, '.*'), '~/.options')
-    rescue
-      return false
+    unless filename
+      basename = File.basename($0, '.*')
+      return true if load(File.expand_path(basename, '~/.options')) rescue nil
+      basename << ".options"
+      return [
+        # XDG
+        ENV['XDG_CONFIG_HOME'],
+        '~/.config',
+        *ENV['XDG_CONFIG_DIRS']&.split(File::PATH_SEPARATOR),
+
+        # Haiku
+        '~/config/settings',
+      ].any? {|dir|
+        next if !dir or dir.empty?
+        load(File.expand_path(basename, dir)) rescue nil
+      }
     end
     begin
       parse(*IO.readlines(filename).each {|s| s.chomp!})
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]