Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import argparse
import contextlib
import functools
import io
import locale
import re
import shutil
import sys
import textwrap
import unittest.mock

from rst2ansi import rst2ansi
from rich.console import Console
from rich.markdown import Markdown

try:
getencoding = locale.getencoding
Expand Down Expand Up @@ -127,15 +130,14 @@ def _encode_description(self, value: str):
return textwrap.dedent(value)
else:
encoding = self._get_encoding()
try:
return rst2ansi(value.encode(encoding), output_encoding=encoding)
except SystemError:
# FALLBACK(PARSER): rst2ansi can raise SystemError on Python 3.14+ due to
# buffer overflow bug in get_terminal_size ioctl call.
# See: https://github.com/Backblaze/B2_Command_Line_Tool/issues/1119
# TODO-REMOVE-BY: When rst2ansi is updated or replaced
if encoding == 'ascii':
return textwrap.dedent(value)

buf = io.StringIO()
console = Console(file=buf, color_system="standard")
console.print(Markdown(textwrap.dedent(value)))
return buf.getvalue().rstrip()

def _get_short_description(self) -> str:
if not self._raw_description:
return ''
Expand Down
36 changes: 15 additions & 21 deletions b2/_internal/b2v3/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,33 @@ class Ls(B2URIMustPointToFolderMixin, B2URIBucketNFolderNameArgMixin, BaseLs):
{BaseLs}

Examples

.. note::

Note the use of quotes, to ensure that special
characters are not expanded by the shell.
> **Note:**
> Note the use of quotes, to ensure that special
> characters are not expanded by the shell.


List csv and tsv files (in any directory, in the whole bucket):

.. code-block::

{NAME} ls --recursive --withWildcard bucketName "*.[ct]sv"
```
{NAME} ls --recursive --withWildcard bucketName "*.[ct]sv"
```


List all info.txt files from directories `b?`, where `?` is any character:

.. code-block::

{NAME} ls --recursive --withWildcard bucketName "b?/info.txt"
```
{NAME} ls --recursive --withWildcard bucketName "b?/info.txt"
```


List all pdf files from directories b0 to b9 (including sub-directories):

.. code-block::

{NAME} ls --recursive --withWildcard bucketName "b[0-9]/*.pdf"
```
{NAME} ls --recursive --withWildcard bucketName "b[0-9]/*.pdf"
```


List all buckets:

.. code-block::

{NAME} ls
```
{NAME} ls
```

Requires capability:

Expand Down
48 changes: 20 additions & 28 deletions b2/_internal/b2v3/rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,37 @@ def get_b2_uri_from_arg(self, args: argparse.Namespace) -> B2URI:
# unit tests without registering any commands.
class Rm(B2URIMustPointToFolderMixin, B2URIBucketNFolderNameArgMixin, BaseRm):
"""
{BaseRm}
{BaseRm}

Examples.

.. note::

Note the use of quotes, to ensure that special
characters are not expanded by the shell.


.. note::

Use with caution. Running examples presented below can cause data-loss.
Examples.
> **Note:**
> Note the use of quotes, to ensure that special
> characters are not expanded by the shell.
> **Note:**
> Use with caution. Running examples presented below can cause data-loss.


Remove all csv and tsv files (in any directory, in the whole bucket):

.. code-block::

{NAME} rm --recursive --withWildcard bucketName "*.[ct]sv"
```
{NAME} rm --recursive --withWildcard bucketName "*.[ct]sv"
```


Remove all info.txt files from buckets bX, where X is any character:

.. code-block::

{NAME} rm --recursive --withWildcard bucketName "b?/info.txt"
```
{NAME} rm --recursive --withWildcard bucketName "b?/info.txt"
```


Remove all pdf files from buckets b0 to b9 (including sub-directories):

.. code-block::

{NAME} rm --recursive --withWildcard bucketName "b[0-9]/*.pdf"
```
{NAME} rm --recursive --withWildcard bucketName "b[0-9]/*.pdf"
```


Requires capability:
Requires capability:

- **listFiles**
- **deleteFiles**
- **bypassGovernance** (if --bypass-governance is used)
- **listFiles**
- **deleteFiles**
- **bypassGovernance** (if --bypass-governance is used)
"""
Loading