Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
88251c94
Commit
88251c94
authored
3 years ago
by
Simon Sapin
Browse files
Options
Downloads
Patches
Plain Diff
Add --no-confirm CLI option
parent
7c47a31e
No related branches found
No related tags found
1 merge request
!1
Initial implementation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+35
-20
35 additions, 20 deletions
src/main.rs
with
35 additions
and
20 deletions
src/main.rs
+
35
−
20
View file @
88251c94
...
...
@@ -4,8 +4,7 @@
use
sha2
::{
Digest
,
Sha256
};
use
std
::
io
::
Seek
;
use
std
::
io
::
Write
;
use
std
::
path
::
Path
;
use
std
::
path
::
PathBuf
;
use
structopt
::
StructOpt
;
#[derive(StructOpt)]
...
...
@@ -8,9 +7,20 @@
use
std
::
path
::
PathBuf
;
use
structopt
::
StructOpt
;
#[derive(StructOpt)]
enum
Args
{
NewDataset
{
directory
:
PathBuf
},
enum
Command
{
NewDataset
(
NewDataset
),
}
#[derive(StructOpt)]
struct
NewDataset
{
/// Skip confirmation prompts
#[structopt(long)]
no_confirm
:
bool
,
/// The directory to archive.
/// The dataset name is taken from the last component of this path.
directory
:
PathBuf
,
}
struct
Megafine
{
...
...
@@ -19,7 +29,7 @@
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Box
<
dyn
std
::
error
::
Error
>>
;
impl
Megafine
{
fn
new_dataset
(
&
self
,
directory
:
&
Path
)
->
Result
<
()
>
{
impl
NewDataset
{
fn
run
(
&
self
,
megafine
:
&
Megafine
)
->
Result
<
()
>
{
println!
(
"Creating a dataset from directory {}"
,
...
...
@@ -24,4 +34,4 @@
println!
(
"Creating a dataset from directory {}"
,
style
(
directory
.display
())
.bold
()
style
(
self
.
directory
.display
())
.bold
()
);
...
...
@@ -27,5 +37,5 @@
);
if
!
std
::
fs
::
metadata
(
&
directory
)
?
.is_dir
()
{
if
!
std
::
fs
::
metadata
(
&
self
.
directory
)
?
.is_dir
()
{
Err
(
"Not a directory"
)
?
}
...
...
@@ -29,7 +39,8 @@
Err
(
"Not a directory"
)
?
}
let
base_name
=
directory
let
base_name
=
self
.directory
.file_name
()
.ok_or
(
"No base name"
)
?
.to_str
()
...
...
@@ -39,7 +50,7 @@
.arg
(
"id"
)
.arg
(
"--id"
)
.arg
(
"-R"
)
.arg
(
&
directory
)
.arg
(
&
self
.
directory
)
.output
()
?
;
let
id
=
if
hg_id_output
.status
.success
()
{
format!
(
"_{}"
,
std
::
str
::
from_utf8
(
&
hg_id_output
.stdout
)
?
.trim
())
...
...
@@ -52,9 +63,9 @@
let
archive_name
=
format!
(
"{}_{}{}.tar.zst"
,
base_name
,
today
,
id
);
let
bold
=
style
(
&
archive_name
)
.bold
();
let
archive_path
=
self
.tmp_dir
.join
(
&
archive_name
);
let
archive_path
=
megafine
.tmp_dir
.join
(
&
archive_name
);
if
archive_path
.exists
()
{
Err
(
format!
(
"tmp/{} already exists"
,
bold
))
?
}
println!
(
"About to create tmp/{}"
,
bold
);
...
...
@@ -56,13 +67,15 @@
if
archive_path
.exists
()
{
Err
(
format!
(
"tmp/{} already exists"
,
bold
))
?
}
println!
(
"About to create tmp/{}"
,
bold
);
let
proceed
=
Confirm
::
new
()
.with_prompt
(
"Continue?"
)
.default
(
false
)
.interact
()
?
;
if
!
proceed
{
Err
(
""
)
?
if
!
self
.no_confirm
{
let
proceed
=
Confirm
::
new
()
.with_prompt
(
"Continue?"
)
.default
(
false
)
.interact
()
?
;
if
!
proceed
{
Err
(
""
)
?
}
}
...
...
@@ -67,6 +80,6 @@
}
let
tmp_file
=
tempfile
::
NamedTempFile
::
new_in
(
&
self
.tmp_dir
)
?
;
let
tmp_file
=
tempfile
::
NamedTempFile
::
new_in
(
&
megafine
.tmp_dir
)
?
;
let
sha
=
Sha256
::
new
();
let
tee
=
Tee
(
tmp_file
,
sha
);
let
level
=
zstd
::
DEFAULT_COMPRESSION_LEVEL
;
...
...
@@ -74,7 +87,7 @@
zstd
.multithread
(
num_cpus
::
get
()
as
_
)
?
;
let
mut
tar
=
tar
::
Builder
::
new
(
zstd
);
tar
.follow_symlinks
(
false
);
tar
.append_dir_all
(
base_name
,
directory
)
?
;
tar
.append_dir_all
(
base_name
,
&
self
.
directory
)
?
;
// Peel the onion
let
zstd
=
tar
.into_inner
()
?
;
let
Tee
(
mut
tmp_file
,
sha
)
=
zstd
.finish
()
?
;
...
...
@@ -88,4 +101,5 @@
Ok
(())
}
}
...
...
@@ -91,4 +105,5 @@
impl
Megafine
{
fn
new
()
->
Result
<
Self
>
{
let
exe
=
std
::
fs
::
canonicalize
(
std
::
env
::
current_exe
()
?
)
?
;
...
...
@@ -117,8 +132,8 @@
fn
main
()
->
Result
<
()
>
{
let
megafine
=
Megafine
::
new
()
?
;
match
Args
::
from_args
()
{
Args
::
NewDataset
{
directory
}
=>
megafine
.new_dataset
(
&
directory
),
match
Command
::
from_args
()
{
Command
::
NewDataset
(
c
)
=>
c
.run
(
&
megafine
),
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment