Module: Argvise::HashExt

Defined in:
lib/argvise/core.rb

Overview

The foundation of HashRefin and HashMixin

Instance Method Summary collapse

Instance Method Details

#to_argv(opts = nil) ⇒ Array<String>

Converts a hash map into GNU-style command-line arguments.

Examples:

Basic usage


require 'argvise'
using Argvise::HashRefin

{ v: true, path: '/path/to/dir' }.to_argv
#=> ["-v", "--path", "/path/to/dir"]

raw_cmd_hash.to_argv is equivalent to:


raw_cmd_hash
  .then(&Argvise.new_proc)
  .with_bsd_style(false)
  .with_kebab_case_flags(true)
  .build

Parameters:

  • opts (Hash, nil) (defaults to: nil)

    See also Argvise.new

Returns:

  • (Array<String>)

See Also:



289
290
291
# File 'lib/argvise/core.rb', line 289

def to_argv(opts = nil)
  Argvise.build(self, opts:)
end

#to_argv_bsd(options = {}) ⇒ Array<String>

Converts a hash map into BSD-style command-line arguments.

Examples:


require 'argvise'
using Argvise::HashRefin

{ path: '/path/to/dir' }.to_argv_bsd
#=> ["-path", "/path/to/dir"]

Parameters:

  • opts (Hash)

Returns:

  • (Array<String>)

See Also:



306
307
308
309
310
311
312
# File 'lib/argvise/core.rb', line 306

def to_argv_bsd(options = {})
  # if options is not Hash Type => {}
  options = {} unless options.is_a?(::Hash)

  opts = options.merge({ bsd_style: true })
  Argvise.build(self, opts:)
end