diff --git a/fpaste b/fpaste index 22d9e65..f36db35 100755 --- a/fpaste +++ b/fpaste @@ -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 is equivalent to fpaste create ", ) 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: