Adds support for -h / --help flag (#97)

* added help flag

* updated .travis.yml

* added the list of all use-case commands

* changed rubocop

* made the necessary minor changes in helplog method and changed rubocop
This commit is contained in:
Rohit Ner 2017-08-16 07:39:02 +05:30 committed by Athitya Kumar
parent 260d8c4255
commit d3e0cd3bb8
4 changed files with 29 additions and 4 deletions

View file

@ -45,10 +45,10 @@ Metrics/ModuleLength:
Max: 200 Max: 200
Metrics/ClassLength: Metrics/ClassLength:
Max: 250 Max: 300
Metrics/ParameterLists: Metrics/ParameterLists:
Max: 10 Max: 15
Style/ParallelAssignment: Style/ParallelAssignment:
Enabled: false Enabled: false
@ -83,7 +83,7 @@ Metrics/AbcSize:
Max: 20 Max: 20
Metrics/MethodLength: Metrics/MethodLength:
Max: 15 Max: 20
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 7 Max: 7

View file

@ -24,6 +24,7 @@ script:
- colorls -sd - colorls -sd
- colorls -sf - colorls -sf
- colorls -t - colorls -t
- colorls -h
- colorls spec/fixtures/symlinks - colorls spec/fixtures/symlinks
- colorls README.md - colorls README.md
- colorls * - colorls *

View file

@ -1,7 +1,7 @@
module ColorLS module ColorLS
class Core class Core
def initialize(input=nil, all: false, report: false, sort: false, show: false, def initialize(input=nil, all: false, report: false, sort: false, show: false,
one_per_line: false, long: false, almost_all: false, tree: false, colors: []) one_per_line: false, long: false, almost_all: false, tree: false, help: false, colors: [])
@input = input || Dir.pwd @input = input || Dir.pwd
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
@all = all @all = all
@ -12,6 +12,7 @@ module ColorLS
@one_per_line = one_per_line @one_per_line = one_per_line
@long = long @long = long
@tree = tree @tree = tree
@help = help
@screen_width = ::TermInfo.screen_size.last @screen_width = ::TermInfo.screen_size.last
@colors = colors @colors = colors
@ -23,6 +24,8 @@ module ColorLS
def ls def ls
return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty? return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty?
return helplog if @help
if @tree if @tree
print "\n" print "\n"
tree_traverse(@input, 0, 2) tree_traverse(@input, 0, 2)
@ -290,5 +293,25 @@ module ColorLS
return prespace_icon if prespace.zero? return prespace_icon if prespace.zero?
' │ ' * (prespace/indent) + prespace_icon + '─' * indent ' │ ' * (prespace/indent) + prespace_icon + '─' * indent
end end
def helplog
print "\nUsage: colorls <command> [-<attributes> (or) --<attributes>] <path> <keyword>\n\n
The available attributes are:\n
\t1 list in a line
\ta (or) all list inclding hidden files in the directory
\tA (or) almost-all list almost all the files
\td (or) dirs list directories only
\tf (or) files list files only
\tl (or) long show list with long format
\tr (or) report detailed report of the files
\tsd (or) sort-dirs sorted and grouped list of directiories followed by files
\tsf (or) sort-files sorted and grouped list of files followed by directiories
\tt (or) tree shows tree view of the directory
\th (or) help show this page\n\n
The available commands are:\n
\tREADME.md lists the README file irrespective of current path
\t* colorls called recursively for each subsequent directory
\t| grep lists the files having the given keyword in the name\n\n"
end
end end
end end

View file

@ -13,6 +13,7 @@ module ColorLS
one_per_line: flag_given?(%w[-1]) || !STDOUT.tty?, one_per_line: flag_given?(%w[-1]) || !STDOUT.tty?,
long: flag_given?(%w[-l --long]), long: flag_given?(%w[-l --long]),
tree: flag_given?(%w[-t --tree]), tree: flag_given?(%w[-t --tree]),
help: flag_given?(%w[-h --help]),
colors: @colors colors: @colors
} }