From a0ea47421499a9e318003a91901477d30c687253 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 11 May 2022 08:48:19 -0700 Subject: [PATCH 1/2] Enhanced RDoc for FileUtils --- lib/fileutils.rb | 66 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/lib/fileutils.rb b/lib/fileutils.rb index c987909..575f1f8 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -236,19 +236,35 @@ def mkdir(list, mode: nil, noop: nil, verbose: nil) module_function :mkdir # - # Creates a directory and all its parent directories. - # For example, + # Creates directories at the paths in the given +list+ + # (an array of strings or a single string), + # also creating ancestor directories as needed; + # returns +list+. + # + # With no keyword arguments, creates a directory at each +path+ in +list+, + # along with any needed ancestor directories, + # by calling: Dir.mkdir(path, mode); + # see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]: + # + # FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] + # FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"] + # + # Keyword arguments: + # + # - mode: integer - also calls File.chmod(mode, path); + # see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod]. + # - noop: true - does not create directories. + # - verbose: true - prints an equivalent command: # - # FileUtils.mkdir_p '/usr/local/lib/ruby' + # FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true) + # FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true) # - # causes to make following directories, if they do not exist. + # Output: # - # * /usr - # * /usr/local - # * /usr/local/lib - # * /usr/local/lib/ruby + # mkdir -p tmp0 tmp1 + # mkdir -p -m 700 tmp2 tmp3 # - # You can pass several directories at a time in a list. + # Raises an exception if for any reason a directory cannot be created. # def mkdir_p(list, mode: nil, noop: nil, verbose: nil) list = fu_list(list) @@ -293,12 +309,34 @@ def fu_mkdir(path, mode) #:nodoc: private_module_function :fu_mkdir # - # Removes one or more directories. + # Removes directories at the paths in the given +list+ + # (an array of strings or a single string); + # returns +list+. + # + # With no keyword arguments, removes the directory at each +path+ in +list+, + # by calling: Dir.rmdir(path, mode); + # see {Dir.rmdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-rmdir]: + # + # FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] + # FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"] + # + # Keyword arguments: + # + # - parents: true - removes successive ancestor directories + # if empty. + # - noop: true - does not remove directories. + # - verbose: true - prints an equivalent command: + # + # FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true) + # FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true) + # + # Output: + # + # rmdir -p tmp0/tmp1 tmp2/tmp3 + # rmdir -p tmp4/tmp5 # - # FileUtils.rmdir 'somedir' - # FileUtils.rmdir %w(somedir anydir otherdir) - # # Does not really remove directory; outputs message. - # FileUtils.rmdir 'somedir', verbose: true, noop: true + # Raises an exception if a directory does not exist + # or if for any reason a directory cannot be removed. # def rmdir(list, parents: nil, noop: nil, verbose: nil) list = fu_list(list) From 4771925feee214b9735c713bab88490a0df3ae1b Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Wed, 11 May 2022 13:33:30 -0500 Subject: [PATCH 2/2] Update lib/fileutils.rb Co-authored-by: Peter Zhu --- lib/fileutils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 575f1f8..367000d 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -314,7 +314,7 @@ def fu_mkdir(path, mode) #:nodoc: # returns +list+. # # With no keyword arguments, removes the directory at each +path+ in +list+, - # by calling: Dir.rmdir(path, mode); + # by calling: Dir.rmdir(path); # see {Dir.rmdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-rmdir]: # # FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]