modify the code according to rubocop

This commit is contained in:
t-mangoe 2022-02-19 11:15:43 +09:00
parent ced1cfebff
commit ba547f299d
2 changed files with 30 additions and 18 deletions

View file

@ -27,8 +27,8 @@ module ColorLS
class Core
def initialize(all: false, sort: false, show: false,
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: true,
indicator_style: 'slash', time_style: '', hard_links_count: true)
reverse: false, hyperlink: false, tree_depth: nil,
indicator_style: 'slash', long_style_options: {})
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
@all = all
@almost_all = almost_all
@ -38,13 +38,13 @@ module ColorLS
@group = group
@show = show
@one_per_line = mode == :one_per_line
init_long_format(mode,show_group,show_user)
init_long_format(mode,long_style_options)
@tree = {mode: mode == :tree, depth: tree_depth}
@horizontal = mode == :horizontal
@git_status = init_git_status(git_status)
@time_style = time_style
@time_style = long_style_options.key?(:time_style) ? long_style_options[:time_style] : ''
@indicator_style = indicator_style
@hard_links_count = hard_links_count
@hard_links_count = long_style_options.key?(:hard_links_count) ? long_style_options[:hard_links_count] : true
init_colors colors
@ -122,10 +122,10 @@ module ColorLS
end
end
def init_long_format(mode, show_group, show_user)
def init_long_format(mode, long_style_options)
@long = mode == :long
@show_group = show_group
@show_user = show_user
@show_group = long_style_options.key?(:show_group) ? long_style_options[:show_group] : true
@show_user = long_style_options.key?(:show_user) ? long_style_options[:show_user] : true
end
def init_git_status(show_git)

View file

@ -105,11 +105,8 @@ module ColorLS
git_status: false,
colors: [],
tree_depth: 3,
show_group: true,
show_user: true,
indicator_style: 'slash',
time_style: '',
hard_links_count: true
long_style_options: {}
}
end
@ -174,21 +171,36 @@ module ColorLS
options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical }
end
def default_long_style_options
{
show_group: true,
show_user: true,
time_style: '',
hard_links_count: true
}
end
def add_long_style_options(options)
options.on('-l', '--long', 'use a long listing format') { @opts[:mode] = :long }
long_style_options = default_long_style_options
options.on('-l', '--long', 'use a long listing format') { @opts[:mode] = :long }
options.on('-o', 'use a long listing format without group information') do
@opts[:mode] = :long
@opts[:show_group] = false
long_style_options[:show_group] = false
end
options.on('-g', 'use a long listing format without owner information') do
@opts[:mode] = :long
@opts[:show_user] = false
long_style_options[:show_user] = false
end
options.on('-G', '--no-group', 'show no group information in a long listing') do
long_style_options[:show_group] = false
end
options.on('-G', '--no-group', 'show no group information in a long listing') { @opts[:show_group] = false }
options.on('--time-style=FORMAT', String, 'use time display format') do |time_style|
@opts[:time_style] = time_style
long_style_options[:time_style] = time_style
end
options.on('--no-hardlinks', 'show no hard links count in a long listing') { @opts[:hard_links_count] = false }
options.on('--no-hardlinks', 'show no hard links count in a long listing') do
long_style_options[:hard_links_count] = false
end
@opts[:long_style_options] = long_style_options
end
def add_general_options(options)