Skip to main content

xy_argparse 模块

Project description

xy_argparse

说明

命令行参数简易工具.

Github地址
Gitee地址

安装

pip install xy_argparse

开始

# main.py
from argparse import Namespace
from xy_argparse.ArgParse import ArgParse

class Runner(ArgParse):

    @property
    def version(self):
        return "0.0.1"

    def __init__(self):
        self.prog = "xy_conda"
        self.description = "conda相关工具"

    def main(self):
        self.default_parser()
        self.add_arguments()
        self.parse_arguments()
        if self.work:
            self.run_arguments()
        else:
            self.parser.print_help()

    def add_arguments(self):
        self.add_argument(
            flag="-w",
            name="--work",
            help_text="""
                工作方式:
                "backup",
                "install",
                "install_pack",
                "load",
            """,
        )

    def on_arguments(
        self,
        name,
        value,
        arguments=None,
    ):
        if name == "work":
            if value == "backup":
                self.backup()
                return False
            elif value == "load":
                self.load()
                return False
            elif value == "install":
                self.install()
                return False
            elif value == "install_pack":
                self.install_pack()
                return False
        return True

    def backup(self):
        print("output backup")

    def load(self):
        print("output load")

    def install(self):
        print("output install")

    def install_pack(self):
        print("output install_pack")

    @property
    def work(self):
        arguments = self.arguments()
        if isinstance(arguments, Namespace):
            return arguments.work
        return None

if __name__ == "__main__":
    runner = Runner()
    runner.main()
Shell
python main.py -w backup
# output backup

捐赠

如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?

Pay-Total

联系方式

微信: yuyangiit
邮箱: 845262968@qq.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xy_argparse-1.0.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xy_argparse-1.0.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file xy_argparse-1.0.3.tar.gz.

File metadata

  • Download URL: xy_argparse-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for xy_argparse-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4d14f4b5a487416958d29457cfd145ccb1f7095cc591732015ffda9aeda853f5
MD5 d41fcd4ab937af37ccd060294579f297
BLAKE2b-256 82b4337de867d61accae916ef21ab8e9a10ea2f006c08ee98e500a8070567dc1

See more details on using hashes here.

File details

Details for the file xy_argparse-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: xy_argparse-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for xy_argparse-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a9bd789e0a569d5537623b98973fafb9b65376658730ed27e2429397f5b5831
MD5 d4050165d4549be98bbf97765f11ac7a
BLAKE2b-256 fbfc20f03aa084e6cc0b0fe672a5807cb9765b909630009ed0b616bc4cd5eb19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page