Class: FFI::Libfuse::FuseArgs
- Inherits:
-
Struct
- Object
- Struct
- FFI::Libfuse::FuseArgs
- Includes:
- Accessors
- Defined in:
- lib/ffi/libfuse/fuse_args.rb
Overview
struct fuse_args
Instance Attribute Summary collapse
-
#argv ⇒ Array<String>
readonly
List of args.
Class Method Summary collapse
-
.create(*argv) ⇒ FuseArgs
Create a fuse_args struct from command line options.
Instance Method Summary collapse
-
#add(arg) ⇒ Object
Add an arg to this arg list.
-
#insert(pos, arg) ⇒ Object
Insert arg at pos in this struct via fuse_opt_insert_arg.
-
#parse!(opts, data = nil, ignore: %i[non_option unmatched],) {|key:, value:, match:, data:, out:| ... } ⇒ self
Option parsing function.
Methods included from Accessors
#ffi_attr_fill, #ffi_attr_reader_member, #ffi_attr_writer_member, #inspect, #to_h
Methods included from Accessors::ClassMethods
#attr_accessor, #attr_reader, #attr_writer, #ffi_attr_accessor, #ffi_attr_reader, #ffi_attr_reader_method, #ffi_attr_readers, #ffi_attr_writer, #ffi_attr_writer_method, #ffi_attr_writers, #ffi_bitflag_accessor, #ffi_bitflag_reader, #ffi_bitflag_writer, #ffi_public_attr_readers, #ffi_public_attr_writers
Instance Attribute Details
#argv ⇒ Array<String> (readonly)
Returns list of args.
47 48 49 50 |
# File 'lib/ffi/libfuse/fuse_args.rb', line 47 ffi_attr_reader(:argv) do # noinspection RubyResolve self[:argv].get_array_of_pointer(0, argc).map(&:read_string) end |
Class Method Details
.create(*argv) ⇒ FuseArgs
Create a fuse_args struct from command line options
26 27 28 29 |
# File 'lib/ffi/libfuse/fuse_args.rb', line 26 def self.create(*argv) argv.unshift('ffi-libfuse') if argv.empty? || argv[0].start_with?('-') new.fill(*argv) end |
Instance Method Details
#add(arg) ⇒ Object
Add an arg to this arg list
54 55 56 |
# File 'lib/ffi/libfuse/fuse_args.rb', line 54 def add(arg) Libfuse.fuse_opt_add_arg(self, arg) end |
#insert(pos, arg) ⇒ Object
Insert arg at pos in this struct via fuse_opt_insert_arg
61 62 63 |
# File 'lib/ffi/libfuse/fuse_args.rb', line 61 def insert(pos, arg) Libfuse.fuse_opt_insert_arg(self, pos, arg) end |
#parse!(opts, data = nil, ignore: %i[non_option unmatched],) {|key:, value:, match:, data:, out:| ... } ⇒ self
Option parsing function
Wraps fuse_opt_parse() in ruby sugar and safety
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ffi/libfuse/fuse_args.rb', line 114 def parse!(opts, data = nil, ignore: %i[non_option unmatched], &block) ignore ||= [] # first create an array of unique symbols such that positive indexes are custom options and negative indexes are # special values (see fuse_opt.h), ie so we can turn the integer received in fuse_opt_proc back into a symbol symbols = opts.values.uniq + %i[discard keep non_option unmatched] # transform our symbol keys into integers suitable for FuseOpts int_opts = opts.transform_values do |v| %i[discard keep].include?(v) ? symbols.rindex(v) - symbols.size : symbols.index(v) end # keep track of opt templates by key so we extract parameter values from arg param_opts, bool_opts = opts.keys.partition { |t| t =~ /(\s+|=)$/ }.map do |opt_list| opt_list.group_by { |t| opts[t] } end fop = fuse_opt_proc(symbols, bool_opts, param_opts, ignore, &block) raise Error unless Libfuse.fuse_opt_parse(self, data, int_opts, fop).zero? self end |