Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
rust
hamster
Commits
4c081145
Commit
4c081145
authored
Sep 26, 2020
by
Daniel Willmann
Browse files
Only print date on the first fact for every day
parent
e624bc00
Pipeline
#49
passed with stages
in 3 minutes and 14 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/bin/hamster/main.rs
View file @
4c081145
...
...
@@ -54,12 +54,12 @@ fn main() -> Result<()> {
let
id
=
hamster
.add_fact
(
&
fact
)
?
;
println!
(
"Added item:"
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
,
true
);
}
(
"del"
,
Some
(
opts
))
=>
{
let
id
=
opts
.value_of
(
"id"
)
.unwrap
()
.parse
()
?
;
println!
(
"Going to delete fact:"
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
,
true
);
hamster
.del_fact
(
id
)
?
;
println!
(
"Deleted"
);
}
...
...
@@ -83,7 +83,7 @@ fn main() -> Result<()> {
let
id
=
hamster
.update_fact
(
&
fact
)
?
;
println!
(
"Updated item:
\n
"
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
,
true
);
}
(
"start"
,
Some
(
opts
))
=>
{
let
range
=
get_rel_range
(
opts
.value_of
(
"start_offset"
)
.unwrap
())
?
;
...
...
@@ -103,7 +103,7 @@ fn main() -> Result<()> {
let
id
=
hamster
.add_fact
(
&
fact
)
?
;
println!
(
"Started working:"
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
,
true
);
}
(
"stop"
,
Some
(
opts
))
=>
{
let
range
=
get_rel_range
(
opts
.value_of
(
"stop_offset"
)
.unwrap
())
?
;
...
...
@@ -132,7 +132,7 @@ fn main() -> Result<()> {
let
id
=
hamster
.update_fact
(
&
fact
)
?
;
println!
(
"Stopped working:"
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
);
print_fact
(
&
hamster
.get_fact
(
id
)
?
,
print_id
,
true
);
}
_
=>
{
let
ranges
=
vec!
[
...
...
@@ -164,8 +164,12 @@ fn list_facts(hamster: &Hamster, range: &FactRange, print_id: bool) -> Result<()
.as_mut_slice
()
.sort_by_key
(|
fact
|
fact
.range
()
.start
.unwrap
());
let
mut
last_date
=
None
;
for
ref
fact
in
facts
.iter
()
{
print_fact
(
fact
,
print_id
);
let
this_date
=
fact
.range
()
.start
.map
(|
dt
|
dt
.date
());
print_fact
(
fact
,
print_id
,
this_date
!=
last_date
);
last_date
=
this_date
;
}
let
duration
=
facts
...
...
@@ -203,7 +207,7 @@ fn get_rel_range(rangestr: &str) -> Result<FactRange> {
Ok
(
rangestr
.parse
::
<
FactRange
>
()
?
)
}
fn
print_fact
(
fact
:
&
Fact
,
print_id
:
bool
)
{
fn
print_fact
(
fact
:
&
Fact
,
print_id
:
bool
,
print_date
:
bool
)
{
let
range
=
fact
.range
();
let
duration_str
=
if
let
Ok
(
duration
)
=
fact
.duration
()
{
...
...
@@ -215,8 +219,14 @@ fn print_fact(fact: &Fact, print_id: bool) {
}
else
{
"??:??"
.to_string
()
};
let
fmt
=
if
print_date
{
"%Y-%m-%d %H:%M"
}
else
{
"%H:%M"
};
println!
(
"{}{:
^
16} - {:^5} ({}) [{:>12}]: {}"
,
"{}{:
>
16} - {:^5} ({}) [{:>12}]: {}"
,
if
print_id
{
if
let
Some
(
id
)
=
fact
.id
()
{
format!
(
"[#{:>04}] "
,
id
)
...
...
@@ -228,7 +238,7 @@ fn print_fact(fact: &Fact, print_id: bool) {
},
range
.start
.map
(|
val
|
{
val
.format
(
"%Y-%m-%d %H:%M"
)
.to_string
()
}
)
.map
(|
val
|
val
.format
(
fmt
)
.to_string
())
.unwrap_or_else
(||
""
.into
()),
range
.end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment