Skip to content

Commit

Permalink
use --kebab-case in code base
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Mar 5, 2024
1 parent dc773b7 commit e419c2f
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 206 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ b2 cancel-all-unfinished-large-files [-h] bucketName
b2 cancel-large-file [-h] fileId
b2 clear-account [-h]
b2 copy-file-by-id [-h] [--fetch-metadata] [--content-type CONTENTTYPE] [--range RANGE] [--info INFO | --no-info] [--destination-server-side-encryption {SSE-B2,SSE-C}] [--destination-server-side-encryption-algorithm {AES256}] [--source-server-side-encryption {SSE-C}] [--source-server-side-encryption-algorithm {AES256}] [--file-retention-mode {compliance,governance}] [--retain-until TIMESTAMP] [--legal-hold {on,off}] sourceFileId destinationBucketName b2FileName
b2 create-bucket [-h] [--bucket-info BUCKETINFO] [--cors-rules CORSRULES] [--file-lock-enabled] [--replication REPLICATION] [--default-server-side-encryption {SSE-B2,none}] [--default-server-side-encryption-algorithm {AES256}] [--lifecycle-rule LIFECYCLERULES | --lifecycleRules LIFECYCLERULES] bucketName {allPublic,allPrivate}
b2 create-bucket [-h] [--bucket-info BUCKETINFO] [--cors-rules CORSRULES] [--file-lock-enabled] [--replication REPLICATION] [--default-server-side-encryption {SSE-B2,none}] [--default-server-side-encryption-algorithm {AES256}] [--lifecycle-rule LIFECYCLERULES | --lifecycle-rules LIFECYCLERULES] bucketName {allPublic,allPrivate}
b2 create-key [-h] [--bucket BUCKET] [--name-prefix NAMEPREFIX] [--duration DURATION] [--all-capabilities] keyName [capabilities]
b2 delete-bucket [-h] bucketName
b2 delete-file-version [-h] [--bypass-governance] [fileName] fileId
Expand All @@ -90,7 +90,7 @@ b2 ls [-h] [--long] [--json] [--replication] [--versions] [-r] [--with-wildcard]
b2 rm [-h] [--dry-run] [--queue-size QUEUESIZE] [--no-progress] [--fail-fast] [--threads THREADS] [--versions] [-r] [--with-wildcard] bucketName [folderName]
b2 get-url [-h] B2_URI
b2 sync [-h] [--no-progress] [--dry-run] [--allow-empty-source] [--exclude-all-symlinks] [--sync-threads SYNCTHREADS] [--download-threads DOWNLOADTHREADS] [--upload-threads UPLOADTHREADS] [--compare-versions {none,modTime,size}] [--compare-threshold MILLIS] [--exclude-regex REGEX] [--include-regex REGEX] [--exclude-dir-regex REGEX] [--exclude-if-modified-after TIMESTAMP] [--threads THREADS] [--destination-server-side-encryption {SSE-B2,SSE-C}] [--destination-server-side-encryption-algorithm {AES256}] [--source-server-side-encryption {SSE-C}] [--source-server-side-encryption-algorithm {AES256}] [--write-buffer-size BYTES] [--skip-hash-verification] [--max-download-streams-per-file MAX_DOWNLOAD_STREAMS_PER_FILE] [--incremental-mode] [--skip-newer | --replace-newer] [--delete | --keep-days DAYS] source destination
b2 update-bucket [-h] [--bucket-info BUCKETINFO] [--cors-rules CORSRULES] [--default-retention-mode {compliance,governance,none}] [--default-retention-period period] [--replication REPLICATION] [--file-lock-enabled] [--default-server-side-encryption {SSE-B2,none}] [--default-server-side-encryption-algorithm {AES256}] [--lifecycle-rule LIFECYCLERULES | --lifecycleRules LIFECYCLERULES] bucketName [{allPublic,allPrivate}]
b2 update-bucket [-h] [--bucket-info BUCKETINFO] [--cors-rules CORSRULES] [--default-retention-mode {compliance,governance,none}] [--default-retention-period period] [--replication REPLICATION] [--file-lock-enabled] [--default-server-side-encryption {SSE-B2,none}] [--default-server-side-encryption-algorithm {AES256}] [--lifecycle-rule LIFECYCLERULES | --lifecycle-rules LIFECYCLERULES] bucketName [{allPublic,allPrivate}]
b2 upload-file [-h] [--content-type CONTENTTYPE] [--sha1 SHA1] [--cache-control CACHE_CONTROL] [--info INFO] [--custom-upload-timestamp CUSTOM_UPLOAD_TIMESTAMP] [--min-part-size MINPARTSIZE] [--threads THREADS] [--no-progress] [--destination-server-side-encryption {SSE-B2,SSE-C}] [--destination-server-side-encryption-algorithm {AES256}] [--legal-hold {on,off}] [--file-retention-mode {compliance,governance}] [--retain-until TIMESTAMP] [--incremental-mode] bucketName localFilePath b2FileName
b2 upload-unbound-stream [-h] [--part-size PARTSIZE] [--unused-buffer-timeout-seconds UNUSEDBUFFERTIMEOUTSECONDS] [--content-type CONTENTTYPE] [--sha1 SHA1] [--cache-control CACHE_CONTROL] [--info INFO] [--custom-upload-timestamp CUSTOM_UPLOAD_TIMESTAMP] [--min-part-size MINPARTSIZE] [--threads THREADS] [--no-progress] [--destination-server-side-encryption {SSE-B2,SSE-C}] [--destination-server-side-encryption-algorithm {AES256}] [--legal-hold {on,off}] [--file-retention-mode {compliance,governance}] [--retain-until TIMESTAMP] bucketName localFilePath b2FileName
b2 update-file-legal-hold [-h] [fileName] fileId {on,off}
Expand Down
3 changes: 2 additions & 1 deletion b2/_internal/_cli/autocomplete_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import argcomplete
import platformdirs

from b2._internal.arg_parser import DeprecatedActionMarker
from b2._internal.version import VERSION


Expand Down Expand Up @@ -119,7 +120,7 @@ def _clean_parser(self, parser: argparse.ArgumentParser) -> None:
parser.register('type', None, identity)

def _get_deprecated_actions(actions):
return [action for action in actions if action.__class__.__name__ == 'DeprecatedAction']
return [action for action in actions if isinstance(action, DeprecatedActionMarker)]

for action in _get_deprecated_actions(parser._actions):
parser._actions.remove(action)
Expand Down
40 changes: 31 additions & 9 deletions b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,38 @@ def deprecated_action_call(self, parser, namespace, values, option_string=None,
return deprecated_action_call


_kebab_to_snake_pattern = re.compile(r'-')
_camel_to_kebab_pattern = re.compile(r'(?<=[a-z])([A-Z])')
_kebab_to_camel_pattern = re.compile(r'-(\w)')


def _camel_to_kebab(s: str):
return re.sub(r'(?<=[a-z])([A-Z])', r'-\1', s).lower()
return _camel_to_kebab_pattern.sub(r'-\1', s).lower()


def _kebab_to_camel(s: str):
return "--" + _kebab_to_camel_pattern.sub(lambda m: m.group(1).upper(), s[2:])


def _kebab_to_snake(s: str):
return _kebab_to_snake_pattern.sub('_', s)


class DeprecatedActionMarker:
pass


def add_normalized_argument(parser, param_name, *args, **kwargs):
kebab_param_name = _camel_to_kebab(param_name)
param_name_kebab = _camel_to_kebab(param_name)
param_name_camel = _kebab_to_camel(param_name_kebab)
dest_name_snake = _kebab_to_snake(param_name_kebab)[2:]
kwargs_kebab = dict(kwargs)
kwargs['help'] = argparse.SUPPRESS
kwargs_camel = kwargs
kwargs_camel['help'] = argparse.SUPPRESS

if 'dest' not in kwargs_kebab:
kwargs_kebab['dest'] = param_name[2:]
kwargs_kebab['dest'] = dest_name_snake
kwargs_camel['dest'] = dest_name_snake

if 'action' in kwargs:
if isinstance(kwargs['action'], str):
Expand All @@ -191,11 +212,12 @@ def add_normalized_argument(parser, param_name, *args, **kwargs):
else:
action = argparse._StoreAction

kwargs['action'] = type(
'DeprecatedAction', (action,), {'__call__': make_deprecated_action_call(action)}
kwargs_camel['action'] = type(
'DeprecatedAction', (action, DeprecatedActionMarker),
{'__call__': make_deprecated_action_call(action)}
)

parser.add_argument(f'{kebab_param_name}', *args, **kwargs_kebab)
parser.add_argument(f'{param_name_kebab}', *args, **kwargs_kebab)

if SUPPORT_CAMEL_CASE_ARGUMENTS:
parser.add_argument(f'{param_name}', *args, **kwargs)
if SUPPORT_CAMEL_CASE_ARGUMENTS and param_name_kebab != param_name_camel:
parser.add_argument(f'{param_name_camel}', *args, **kwargs_camel)
Loading

0 comments on commit e419c2f

Please sign in to comment.