fpaste: add file path shortcut (fpaste <file>)
Some checks failed
CI / Lint & Format (push) Failing after 15s
CI / Tests (push) Has been skipped
CI / Security Scan (push) Failing after 21s

This commit is contained in:
Username
2025-12-20 17:56:34 +01:00
parent cdf8de5a8b
commit 85110b2570

43
fpaste
View File

@@ -695,10 +695,51 @@ def cmd_cert(args, config):
print(fingerprint)
def is_file_path(arg):
"""Check if argument looks like a file path."""
if not arg or arg.startswith("-"):
return False
# Check if it's an existing file
if Path(arg).exists():
return True
# Check if it looks like a path (contains / or \ or common extensions)
if "/" in arg or "\\" in arg:
return True
# Check for common file extensions
if "." in arg and not arg.startswith("."):
ext = arg.rsplit(".", 1)[-1].lower()
if ext in ("txt", "md", "py", "js", "json", "yaml", "yml", "xml", "html",
"css", "sh", "bash", "c", "cpp", "h", "go", "rs", "java",
"rb", "php", "sql", "log", "conf", "cfg", "ini", "png",
"jpg", "jpeg", "gif", "pdf", "zip", "tar", "gz"):
return True
return False
def main():
# Pre-process arguments: if first positional looks like a file, insert "create"
args_to_parse = sys.argv[1:]
commands = {"create", "c", "new", "get", "g", "delete", "d", "rm", "info", "i", "cert", "pki"}
# Find first non-option argument
i = 0
while i < len(args_to_parse):
arg = args_to_parse[i]
if arg in ("-s", "--server"):
i += 2 # Skip -s and its value
continue
if arg.startswith("-"):
i += 1
continue
# Found first positional - check if it's a command or a file
if arg not in commands and is_file_path(arg):
args_to_parse.insert(i, "create")
break
parser = argparse.ArgumentParser(
prog="fpaste",
description="FlaskPaste command-line client",
epilog="Shortcut: fpaste <file> is equivalent to fpaste create <file>",
)
parser.add_argument(
"-s",
@@ -780,7 +821,7 @@ def main():
help="update config file with CA cert path (requires -o)",
)
args = parser.parse_args()
args = parser.parse_args(args_to_parse)
config = get_config()
if args.server: