Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
23e5d3ce
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,发现更多精彩内容 >>
提交
23e5d3ce
编写于
1月 12, 2015
作者:
B
Benjamin Sago
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow for different types of failure
上级
3f08836c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
27 deletion
+45
-27
src/exa.rs
src/exa.rs
+18
-10
src/options.rs
src/options.rs
+27
-17
未找到文件。
src/exa.rs
浏览文件 @
23e5d3ce
...
...
@@ -7,11 +7,12 @@ extern crate users;
use
std
::
io
::
FileType
;
use
std
::
io
::
fs
;
use
std
::
os
;
use
std
::
os
::{
args
,
set_exit_status
}
;
use
dir
::
Dir
;
use
file
::
File
;
use
options
::
Options
;
use
options
::
Error
::
*
;
pub
mod
column
;
pub
mod
dir
;
...
...
@@ -21,15 +22,6 @@ pub mod options;
pub
mod
output
;
pub
mod
term
;
fn
main
()
{
let
args
:
Vec
<
String
>
=
os
::
args
();
match
Options
::
getopts
(
args
)
{
Err
(
error_code
)
=>
os
::
set_exit_status
(
error_code
),
Ok
(
options
)
=>
exa
(
&
options
),
};
}
fn
exa
(
options
:
&
Options
)
{
let
mut
dirs
:
Vec
<
String
>
=
vec!
[];
let
mut
files
:
Vec
<
File
>
=
vec!
[];
...
...
@@ -92,3 +84,19 @@ fn exa(options: &Options) {
};
}
}
fn
main
()
{
let
args
:
Vec
<
String
>
=
args
();
match
Options
::
getopts
(
args
)
{
Ok
(
options
)
=>
exa
(
&
options
),
Err
(
Help
(
text
))
=>
{
println!
(
"{}"
,
text
);
set_exit_status
(
2
);
},
Err
(
InvalidOptions
(
e
))
=>
{
println!
(
"{}"
,
e
);
set_exit_status
(
3
);
},
};
}
src/options.rs
浏览文件 @
23e5d3ce
...
...
@@ -17,18 +17,22 @@ pub enum SortField {
impl
Copy
for
SortField
{
}
impl
SortField
{
fn
from_word
(
word
:
String
)
->
SortField
{
fn
from_word
(
word
:
String
)
->
Result
<
SortField
,
Error
>
{
match
word
.as_slice
()
{
"name"
=>
SortField
::
Name
,
"size"
=>
SortField
::
Size
,
"ext"
=>
SortField
::
Extension
,
"none"
=>
SortField
::
Unsorted
,
"inode"
=>
SortField
::
FileInode
,
_
=>
panic!
(
"Invalid sorting order"
),
"name"
=>
Ok
(
SortField
::
Name
)
,
"size"
=>
Ok
(
SortField
::
Size
)
,
"ext"
=>
Ok
(
SortField
::
Extension
)
,
"none"
=>
Ok
(
SortField
::
Unsorted
)
,
"inode"
=>
Ok
(
SortField
::
FileInode
)
,
field
=>
Err
(
no_sort_field
(
field
))
}
}
}
fn
no_sort_field
(
field
:
&
str
)
->
Error
{
Error
::
InvalidOptions
(
getopts
::
Fail
::
UnrecognizedOption
(
format!
(
"--sort {}"
,
field
)))
}
pub
struct
Options
{
pub
list_dirs
:
bool
,
path_strs
:
Vec
<
String
>
,
...
...
@@ -38,9 +42,14 @@ pub struct Options {
pub
view
:
View
,
}
pub
enum
Error
{
InvalidOptions
(
getopts
::
Fail
),
Help
(
String
),
}
impl
Options
{
pub
fn
getopts
(
args
:
Vec
<
String
>
)
->
Result
<
Options
,
isize
>
{
let
opts
=
[
pub
fn
getopts
(
args
:
Vec
<
String
>
)
->
Result
<
Options
,
Error
>
{
let
opts
=
&
[
getopts
::
optflag
(
"1"
,
"oneline"
,
"display one entry per line"
),
getopts
::
optflag
(
"a"
,
"all"
,
"show dot-files"
),
getopts
::
optflag
(
"b"
,
"binary"
,
"use binary prefixes in file sizes"
),
...
...
@@ -58,25 +67,26 @@ impl Options {
getopts
::
optflag
(
"?"
,
"help"
,
"show list of command-line options"
),
];
let
matches
=
match
getopts
::
getopts
(
args
.tail
(),
&
opts
)
{
let
matches
=
match
getopts
::
getopts
(
args
.tail
(),
opts
)
{
Ok
(
m
)
=>
m
,
Err
(
e
)
=>
{
println!
(
"Invalid options: {}"
,
e
);
return
Err
(
1
);
}
Err
(
e
)
=>
return
Err
(
Error
::
InvalidOptions
(
e
)),
};
if
matches
.opt_present
(
"help"
)
{
println!
(
"exa - ls with more features
\n\n
{}"
,
getopts
::
usage
(
"Usage:
\n
exa [options] [files...]"
,
&
opts
));
return
Err
(
2
);
return
Err
(
Error
::
Help
(
getopts
::
usage
(
"Usage:
\n
exa [options] [files...]"
,
opts
)));
}
let
sort_field
=
match
matches
.opt_str
(
"sort"
)
{
Some
(
word
)
=>
try!
(
SortField
::
from_word
(
word
)),
None
=>
SortField
::
Name
,
};
Ok
(
Options
{
list_dirs
:
matches
.opt_present
(
"list-dirs"
),
path_strs
:
if
matches
.free
.is_empty
()
{
vec!
[
"."
.to_string
()
]
}
else
{
matches
.free
.clone
()
},
reverse
:
matches
.opt_present
(
"reverse"
),
show_invisibles
:
matches
.opt_present
(
"all"
),
sort_field
:
matches
.opt_str
(
"sort"
)
.map
(|
word
|
SortField
::
from_word
(
word
))
.unwrap_or
(
SortField
::
Name
)
,
sort_field
:
sort_field
,
view
:
Options
::
view
(
&
matches
),
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录