mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Merge pull request #499 from t-mangoe/no-hardlinks
This commit is contained in:
commit
ce46ab1e87
5 changed files with 76 additions and 19 deletions
|
@ -27,8 +27,8 @@ module ColorLS
|
|||
class Core
|
||||
def initialize(all: false, sort: false, show: false,
|
||||
mode: nil, show_git: false, almost_all: false, colors: [], group: nil,
|
||||
reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, show_group: true, show_user: true,
|
||||
indicator_style: 'slash', time_style: '')
|
||||
reverse: false, hyperlink: false, tree_depth: nil, show_inode: false,
|
||||
indicator_style: 'slash', long_style_options: {})
|
||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||
@all = all
|
||||
@almost_all = almost_all
|
||||
|
@ -39,13 +39,13 @@ module ColorLS
|
|||
@show = show
|
||||
@one_per_line = mode == :one_per_line
|
||||
@show_inode = show_inode
|
||||
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
|
||||
@show_git = show_git
|
||||
@git_status = init_git_status(show_git)
|
||||
@time_style = time_style
|
||||
@time_style = long_style_options.key?(:time_style) ? long_style_options[:time_style] : ''
|
||||
@indicator_style = indicator_style
|
||||
@hard_links_count = long_style_options.key?(:hard_links_count) ? long_style_options[:hard_links_count] : true
|
||||
# how much characters an item occupies besides its name
|
||||
@additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)
|
||||
|
||||
|
@ -133,13 +133,14 @@ 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)
|
||||
@show_git = show_git
|
||||
return {}.freeze unless show_git
|
||||
|
||||
# stores git status information per directory
|
||||
|
@ -310,7 +311,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)]
|
||||
|
|
|
@ -106,10 +106,8 @@ module ColorLS
|
|||
colors: [],
|
||||
tree_depth: 3,
|
||||
show_inode: false,
|
||||
show_group: true,
|
||||
show_user: true,
|
||||
indicator_style: 'slash',
|
||||
time_style: ''
|
||||
long_style_options: {}
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -178,20 +176,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') do
|
||||
long_style_options[:hard_links_count] = false
|
||||
end
|
||||
@opts[:long_style_options] = long_style_options
|
||||
end
|
||||
|
||||
def add_general_options(options)
|
||||
|
|
|
@ -577,4 +577,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
|
||||
|
|
|
@ -38,6 +38,7 @@ OK colorls --report
|
|||
OK colorls --report=long
|
||||
OK colorls --report=short
|
||||
OK colorls --inode
|
||||
OK colorls -l --no-hardlinks
|
||||
|
||||
LC_ALL=C OK colorls spec/fixtures/
|
||||
LC_ALL=C OK colorls --git spec/fixtures/
|
||||
|
|
4
test/run
4
test/run
|
@ -94,10 +94,10 @@ function OUT() {
|
|||
|
||||
function summary() {
|
||||
if [[ $ERRORS -gt 0 ]]; then
|
||||
printf '\n\n %d of %d tests failed.' "$ERRORS" "$TESTS" >&2
|
||||
printf '\n\n %d of %d tests failed.\n\n' "$ERRORS" "$TESTS" >&2
|
||||
exit 1
|
||||
else
|
||||
printf '\n\n %d tests passed.' "$TESTS" >&2
|
||||
printf '\n\n %d tests passed.\n\n' "$TESTS" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue