Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
763e833b
E
Exa
项目概览
vnotepad
/
Exa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Exa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
763e833b
编写于
6月 23, 2017
作者:
B
Benjamin Sago
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'help!'
上级
aaa8876f
81c5d8b7
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
150 addition
and
49 deletion
+150
-49
src/bin/main.rs
src/bin/main.rs
+23
-7
src/options/filter.rs
src/options/filter.rs
+6
-4
src/options/help.rs
src/options/help.rs
+36
-7
src/options/misfire.rs
src/options/misfire.rs
+10
-8
src/options/mod.rs
src/options/mod.rs
+7
-19
src/options/view.rs
src/options/view.rs
+5
-4
xtests/help
xtests/help
+42
-0
xtests/help_long
xtests/help_long
+18
-0
xtests/run.sh
xtests/run.sh
+3
-0
未找到文件。
src/bin/main.rs
浏览文件 @
763e833b
...
...
@@ -5,28 +5,44 @@ use std::env::args_os;
use
std
::
io
::{
stdout
,
stderr
,
Write
,
ErrorKind
};
use
std
::
process
::
exit
;
fn
main
()
{
let
args
=
args_os
()
.skip
(
1
);
let
mut
stdout
=
stdout
();
match
Exa
::
new
(
args
,
&
mut
stdout
)
{
match
Exa
::
new
(
args
,
&
mut
stdout
())
{
Ok
(
mut
exa
)
=>
{
match
exa
.run
()
{
Ok
(
exit_status
)
=>
exit
(
exit_status
),
Err
(
e
)
=>
{
match
e
.kind
()
{
ErrorKind
::
BrokenPipe
=>
exit
(
0
),
ErrorKind
::
BrokenPipe
=>
exit
(
exits
::
SUCCESS
),
_
=>
{
writeln!
(
stderr
(),
"{}"
,
e
)
.unwrap
();
exit
(
1
);
exit
(
exits
::
RUNTIME_ERROR
);
},
};
}
};
},
Err
(
e
)
=>
{
Err
(
ref
e
)
if
e
.is_error
()
=>
{
writeln!
(
stderr
(),
"{}"
,
e
)
.unwrap
();
exit
(
e
.error_code
());
exit
(
exits
::
OPTIONS_ERROR
);
},
Err
(
ref
e
)
=>
{
writeln!
(
stdout
(),
"{}"
,
e
)
.unwrap
();
exit
(
exits
::
SUCCESS
);
},
};
}
extern
crate
libc
;
#[allow(trivial_numeric_casts)]
mod
exits
{
use
libc
::{
self
,
c_int
};
pub
const
SUCCESS
:
c_int
=
libc
::
EXIT_SUCCESS
;
pub
const
RUNTIME_ERROR
:
c_int
=
libc
::
EXIT_FAILURE
;
pub
const
OPTIONS_ERROR
:
c_int
=
3
as
c_int
;
}
src/options/filter.rs
浏览文件 @
763e833b
...
...
@@ -225,6 +225,11 @@ impl SortField {
/// argument. This will return `Err` if the option is there, but does not
/// correspond to a valid field.
fn
deduce
(
matches
:
&
getopts
::
Matches
)
->
Result
<
SortField
,
Misfire
>
{
const
SORTS
:
&
[
&
str
]
=
&
[
"name"
,
"Name"
,
"size"
,
"extension"
,
"Extension"
,
"modified"
,
"accessed"
,
"created"
,
"inode"
,
"none"
];
if
let
Some
(
word
)
=
matches
.opt_str
(
"sort"
)
{
match
&*
word
{
"name"
|
"filename"
=>
Ok
(
SortField
::
Name
(
SortCase
::
Sensitive
)),
...
...
@@ -237,10 +242,7 @@ impl SortField {
"cr"
|
"created"
=>
Ok
(
SortField
::
CreatedDate
),
"none"
=>
Ok
(
SortField
::
Unsorted
),
"inode"
=>
Ok
(
SortField
::
FileInode
),
field
=>
Err
(
Misfire
::
bad_argument
(
"sort"
,
field
,
&
[
"name"
,
"Name"
,
"size"
,
"extension"
,
"Extension"
,
"modified"
,
"accessed"
,
"created"
,
"inode"
,
"none"
]
))
field
=>
Err
(
Misfire
::
bad_argument
(
"sort"
,
field
,
SORTS
))
}
}
else
{
...
...
src/options/help.rs
浏览文件 @
763e833b
use
std
::
fmt
;
pub
static
OPTIONS
:
&
str
=
r##"
static
OPTIONS
:
&
str
=
r##"
-?, --help show list of command-line options
-v, --version show version of exa
...
...
@@ -23,10 +25,9 @@ FILTERING AND SORTING OPTIONS
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
Valid sort fields: name, Name, extension, Extension, size,
modified, accessed, created, inode, none
"##
;
pub
static
LONG_OPTIONS
:
&
str
=
r##"
static
LONG_OPTIONS
:
&
str
=
r##"
LONG VIEW OPTIONS
-b, --binary list file sizes with binary prefixes
-B, --bytes list file sizes in bytes, without any prefixes
...
...
@@ -39,8 +40,36 @@ LONG VIEW OPTIONS
-S, --blocks show number of file system blocks
-t, --time FIELD which timestamp field to list (modified, accessed, created)
-u, --accessed use the accessed timestamp field
-U, --created use the created timestamp field
"##
;
-U, --created use the created timestamp field"##
;
static
GIT_HELP
:
&
str
=
r##" --git list each file's Git status, if tracked"##
;
static
EXTENDED_HELP
:
&
str
=
r##" -@, --extended list each file's extended attributes and sizes"##
;
#[derive(PartialEq,
Debug)]
pub
struct
HelpString
{
pub
only_long
:
bool
,
pub
git
:
bool
,
pub
xattrs
:
bool
,
}
impl
fmt
::
Display
for
HelpString
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
Result
<
(),
fmt
::
Error
>
{
try!
(
write!
(
f
,
"Usage:
\n
exa [options] [files...]
\n
"
));
if
!
self
.only_long
{
try!
(
write!
(
f
,
"{}"
,
OPTIONS
));
}
try!
(
write!
(
f
,
"{}"
,
LONG_OPTIONS
));
if
self
.git
{
try!
(
write!
(
f
,
"
\n
{}"
,
GIT_HELP
));
}
if
self
.xattrs
{
try!
(
write!
(
f
,
"
\n
{}"
,
EXTENDED_HELP
));
}
pub
static
GIT_HELP
:
&
str
=
r##" --git list each file's Git status, if tracked"##
;
pub
static
EXTENDED_HELP
:
&
str
=
r##" -@, --extended list each file's extended attributes and sizes"##
;
Ok
(())
}
}
src/options/misfire.rs
浏览文件 @
763e833b
...
...
@@ -4,10 +4,12 @@ use std::num::ParseIntError;
use
getopts
;
use
glob
;
use
options
::
help
::
HelpString
;
/// A list of legal choices for an argument-taking option
#[derive(PartialEq,
Debug)]
pub
struct
Choices
(
Vec
<&
'static
str
>
);
pub
struct
Choices
(
&
'static
[
&
'static
str
]
);
impl
fmt
::
Display
for
Choices
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
...
...
@@ -28,7 +30,7 @@ pub enum Misfire {
/// The user asked for help. This isn’t strictly an error, which is why
/// this enum isn’t named Error!
Help
(
String
),
Help
(
Help
String
),
/// The user wanted the version number.
Version
,
...
...
@@ -54,11 +56,11 @@ pub enum Misfire {
impl
Misfire
{
/// The OS return code this misfire should signify.
pub
fn
error_code
(
&
self
)
->
i32
{
pub
fn
is_error
(
&
self
)
->
bool
{
match
*
self
{
Misfire
::
Help
(
_
)
=>
0
,
Misfire
::
Version
=>
0
,
_
=>
3
,
Misfire
::
Help
(
_
)
=>
false
,
Misfire
::
Version
=>
false
,
_
=>
true
,
}
}
...
...
@@ -66,10 +68,10 @@ impl Misfire {
/// argument. This has to use one of the `getopts` failure
/// variants--it’s meant to take just an option name, rather than an
/// option *and* an argument, but it works just as well.
pub
fn
bad_argument
(
option
:
&
str
,
otherwise
:
&
str
,
legal
:
&
[
&
'static
str
])
->
Misfire
{
pub
fn
bad_argument
(
option
:
&
str
,
otherwise
:
&
str
,
legal
:
&
'static
[
&
'static
str
])
->
Misfire
{
Misfire
::
BadArgument
(
getopts
::
Fail
::
UnrecognizedOption
(
format!
(
"--{} {}"
,
option
,
otherwise
)),
Choices
(
legal
.into
()
))
option
,
otherwise
)),
Choices
(
legal
))
}
}
...
...
src/options/mod.rs
浏览文件 @
763e833b
...
...
@@ -12,7 +12,7 @@ mod filter;
pub
use
self
::
filter
::{
FileFilter
,
SortField
,
SortCase
};
mod
help
;
use
self
::
help
::
*
;
use
self
::
help
::
HelpString
;
mod
misfire
;
pub
use
self
::
misfire
::
Misfire
;
...
...
@@ -103,25 +103,13 @@ impl Options {
};
if
matches
.opt_present
(
"help"
)
{
let
mut
help_string
=
"Usage:
\n
exa [options] [files...]
\n
"
.to_owned
();
if
!
matches
.opt_present
(
"long"
)
{
help_string
.push_str
(
OPTIONS
);
}
help_string
.push_str
(
LONG_OPTIONS
);
if
cfg!
(
feature
=
"git"
)
{
help_string
.push_str
(
GIT_HELP
);
help_string
.push
(
'\n'
);
}
if
xattr
::
ENABLED
{
help_string
.push_str
(
EXTENDED_HELP
);
help_string
.push
(
'\n'
);
}
let
help
=
HelpString
{
only_long
:
matches
.opt_present
(
"long"
),
git
:
cfg!
(
feature
=
"git"
),
xattrs
:
xattr
::
ENABLED
,
};
return
Err
(
Misfire
::
Help
(
help
_string
));
return
Err
(
Misfire
::
Help
(
help
));
}
else
if
matches
.opt_present
(
"version"
)
{
return
Err
(
Misfire
::
Version
);
...
...
src/options/view.rs
浏览文件 @
763e833b
...
...
@@ -294,12 +294,12 @@ impl TimeTypes {
return
Err
(
Misfire
::
Useless
(
"accessed"
,
true
,
"time"
));
}
static
TIMES
:
&
[
&
str
]
=
&
[
"modified"
,
"accessed"
,
"created"
];
match
&*
word
{
"mod"
|
"modified"
=>
Ok
(
TimeTypes
{
accessed
:
false
,
modified
:
true
,
created
:
false
}),
"acc"
|
"accessed"
=>
Ok
(
TimeTypes
{
accessed
:
true
,
modified
:
false
,
created
:
false
}),
"cr"
|
"created"
=>
Ok
(
TimeTypes
{
accessed
:
false
,
modified
:
false
,
created
:
true
}),
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"time"
,
otherwise
,
&
[
"modified"
,
"accessed"
,
"created"
])),
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"time"
,
otherwise
,
TIMES
))
}
}
else
if
modified
||
created
||
accessed
{
...
...
@@ -342,13 +342,14 @@ impl TerminalColours {
/// Determine which terminal colour conditions to use.
fn
deduce
(
matches
:
&
getopts
::
Matches
)
->
Result
<
TerminalColours
,
Misfire
>
{
const
COLOURS
:
&
[
&
str
]
=
&
[
"always"
,
"auto"
,
"never"
];
if
let
Some
(
word
)
=
matches
.opt_str
(
"color"
)
.or_else
(||
matches
.opt_str
(
"colour"
))
{
match
&*
word
{
"always"
=>
Ok
(
TerminalColours
::
Always
),
"auto"
|
"automatic"
=>
Ok
(
TerminalColours
::
Automatic
),
"never"
=>
Ok
(
TerminalColours
::
Never
),
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"color"
,
otherwise
,
&
[
"always"
,
"auto"
,
"never"
]))
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"color"
,
otherwise
,
COLOURS
))
}
}
else
{
...
...
xtests/help
0 → 100644
浏览文件 @
763e833b
Usage:
exa [options] [files...]
-?, --help show list of command-line options
-v, --version show version of exa
DISPLAY OPTIONS
-1, --oneline display one entry per line
-l, --long display extended file metadata as a table
-G, --grid display entries as a grid (default)
-x, --across sort the grid across, rather than downwards
-R, --recurse recurse into directories
-T, --tree recurse into directories as a tree
-F, --classify display type indicator by file names
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
--colo[u]r-scale highlight levels of file sizes distinctly
FILTERING AND SORTING OPTIONS
-a, --all don't hide hidden and 'dot' files
-d, --list-dirs list directories like regular files
-r, --reverse reverse the sort order
-s, --sort SORT_FIELD which field to sort by:
--group-directories-first list directories before other files
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
Valid sort fields: name, Name, extension, Extension, size,
modified, accessed, created, inode, none
LONG VIEW OPTIONS
-b, --binary list file sizes with binary prefixes
-B, --bytes list file sizes in bytes, without any prefixes
-g, --group list each file's group
-h, --header add a header row to each column
-H, --links list each file's number of hard links
-i, --inode list each file's inode number
-L, --level DEPTH limit the depth of recursion
-m, --modified use the modified timestamp field
-S, --blocks show number of file system blocks
-t, --time FIELD which timestamp field to list (modified, accessed, created)
-u, --accessed use the accessed timestamp field
-U, --created use the created timestamp field
--git list each file's Git status, if tracked
-@, --extended list each file's extended attributes and sizes
xtests/help_long
0 → 100644
浏览文件 @
763e833b
Usage:
exa [options] [files...]
LONG VIEW OPTIONS
-b, --binary list file sizes with binary prefixes
-B, --bytes list file sizes in bytes, without any prefixes
-g, --group list each file's group
-h, --header add a header row to each column
-H, --links list each file's number of hard links
-i, --inode list each file's inode number
-L, --level DEPTH limit the depth of recursion
-m, --modified use the modified timestamp field
-S, --blocks show number of file system blocks
-t, --time FIELD which timestamp field to list (modified, accessed, created)
-u, --accessed use the accessed timestamp field
-U, --created use the created timestamp field
--git list each file's Git status, if tracked
-@, --extended list each file's extended attributes and sizes
xtests/run.sh
浏览文件 @
763e833b
...
...
@@ -109,5 +109,8 @@ $exa $testcases/links/* -1 | diff -q - $results/links_1_files || exit 1
$exa
$testcases
/git/additions
-l
--git
2>&1 | diff
-q
-
$results
/git_additions
||
exit
1
$exa
$testcases
/git/edits
-l
--git
2>&1 | diff
-q
-
$results
/git_edits
||
exit
1
# And finally...
$exa
--help
| diff
-q
-
$results
/help
||
exit
1
$exa
--help
--long
| diff
-q
-
$results
/help_long
||
exit
1
echo
"All the tests passed!"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录