#!/usr/bin/env ruby require 'pathname' $: << Pathname.new($0).expand_path.dirname+'lib' require 'base' require 'active_support/all' require 'json' class Tivate < Base def initialize super sh.alias_command :lsblk_json, *%w[lsblk --json --fs], return: :string end def listing *devices, reverse: nil, only_fs: nil, &exe return to_enum( __method__, *devices, reverse: reverse, only_fs: only_fs) unless block_given? return nil if devices.empty? reverse = false if reverse.nil? only_fs = false if only_fs.nil? l = lambda do |e| case e['fstype'] when 'LVM2_member' e[:isfs] = false yield e if not only_fs and not reverse (e['children']||[]).each &l yield e if not only_fs and reverse when *%w[ext2 ext3 ext4 xfs] e[:isfs] = true yield e end end devices.each do |dev| if dev.exist? data = JSON.parse sh.lsblk_json( dev) data['blockdevices'].each &l end end end end cmd = Pathname.new $0 case ARGV[0] when '-h', '--help' puts <