Gitlab Community Edition Instance
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cdstar
pycdstar3
Commits
c6e3cdf9
Commit
c6e3cdf9
authored
Oct 28, 2019
by
mhellka
Browse files
Added 'rm' command
parent
192beea9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/pycdstar3/cli/commands/rm.py
0 → 100644
View file @
c6e3cdf9
"""
Delete files from an archive.
"""
from
contextlib
import
ExitStack
# TODO: Delete directories or glob patterns
from
pycdstar3
import
ApiError
def
register
(
subparsers
):
parser
=
subparsers
.
add_parser
(
"rm"
,
help
=
__doc__
.
strip
().
splitlines
()[
0
],
description
=
__doc__
)
parser
.
add_argument
(
"-f"
,
"--force"
,
action
=
"store_true"
,
help
=
"Ignore missing files"
)
parser
.
add_argument
(
"ARCHIVE"
,
help
=
"Archive ID"
)
parser
.
add_argument
(
"FILES"
,
nargs
=
"+"
,
help
=
"File(s) to remove."
)
parser
.
set_defaults
(
main
=
remove_files
)
def
remove_files
(
ctx
,
args
):
client
=
ctx
.
client
vault
=
ctx
.
vault
archive
=
args
.
ARCHIVE
files
=
args
.
FILES
force
=
args
.
force
with
ExitStack
()
as
stack
:
if
len
(
files
)
>
1
:
stack
.
enter_context
(
client
.
begin
(
autocommit
=
True
))
for
i
,
file
in
enumerate
(
files
):
file
=
file
.
lstrip
(
"/"
)
try
:
ctx
.
print
(
"Deleting {}/{}"
.
format
(
archive
,
file
))
client
.
delete_file
(
vault
,
archive
,
file
)
except
ApiError
as
e
:
if
e
.
error
==
"FileNotFound"
and
force
:
continue
raise
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