mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
add --no-hardlinks option
This commit is contained in:
parent
296d7f0f18
commit
ced1cfebff
3 changed files with 47 additions and 3 deletions
|
@ -28,7 +28,7 @@ module ColorLS
|
|||
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: '')
|
||||
indicator_style: 'slash', time_style: '', hard_links_count: true)
|
||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||
@all = all
|
||||
@almost_all = almost_all
|
||||
|
@ -44,6 +44,7 @@ module ColorLS
|
|||
@git_status = init_git_status(git_status)
|
||||
@time_style = time_style
|
||||
@indicator_style = indicator_style
|
||||
@hard_links_count = hard_links_count
|
||||
|
||||
init_colors colors
|
||||
|
||||
|
@ -295,7 +296,8 @@ module ColorLS
|
|||
|
||||
links = content.nlink.to_s.rjust(@linklength)
|
||||
|
||||
line_array = [mode_info(content.stats), links]
|
||||
line_array = [mode_info(content.stats)]
|
||||
line_array.push links if @hard_links_count
|
||||
line_array.push user_info(content) if @show_user
|
||||
line_array.push group_info(content.group) if @show_group
|
||||
line_array.concat [size_info(content.size), mtime_info(content.mtime)]
|
||||
|
|
|
@ -108,7 +108,8 @@ module ColorLS
|
|||
show_group: true,
|
||||
show_user: true,
|
||||
indicator_style: 'slash',
|
||||
time_style: ''
|
||||
time_style: '',
|
||||
hard_links_count: true
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -187,6 +188,7 @@ module ColorLS
|
|||
options.on('--time-style=FORMAT', String, 'use time display format') do |time_style|
|
||||
@opts[:time_style] = time_style
|
||||
end
|
||||
options.on('--no-hardlinks', 'show no hard links count in a long listing') { @opts[:hard_links_count] = false }
|
||||
end
|
||||
|
||||
def add_general_options(options)
|
||||
|
|
|
@ -558,4 +558,44 @@ RSpec.describe ColorLS::Flags do
|
|||
|
||||
it { expect { subject }.to output(/#{mtime.strftime("%y-%m-%d %k:%M")}/).to_stdout }
|
||||
end
|
||||
|
||||
context 'with --no-hardlinks flag in a listing format' do
|
||||
let(:args) { ['-l', '--no-hardlink', "#{FIXTURES}/a.txt"] }
|
||||
|
||||
before do
|
||||
file_info = instance_double(
|
||||
'FileInfo',
|
||||
group: 'sys',
|
||||
mtime: Time.now,
|
||||
directory?: false,
|
||||
owner: 'user',
|
||||
name: 'a.txt',
|
||||
show: 'a.txt',
|
||||
nlink: 987,
|
||||
size: 128,
|
||||
blockdev?: false,
|
||||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: false,
|
||||
stats: OpenStruct.new(
|
||||
mode: 0o444, # read for user, owner, other
|
||||
setuid?: true,
|
||||
setgid?: true,
|
||||
sticky?: true
|
||||
),
|
||||
executable?: false
|
||||
)
|
||||
|
||||
allow(ColorLS::FileInfo).to receive(:new).with(
|
||||
path: File.join(FIXTURES, 'a.txt'),
|
||||
parent: FIXTURES,
|
||||
name: 'a.txt',
|
||||
link_info: true
|
||||
) { file_info }
|
||||
end
|
||||
|
||||
it 'lists without hard links count' do
|
||||
expect { subject }.not_to output(/987/).to_stdout
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue