Skip to main content

xy_argparse

简体中文 繁體中文 English

说明

命令行参数简易工具.

源码仓库

Github Gitee GitCode

安装

# bash
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()
        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()
# bash
python main.py -w backup
# output backup

许可证

xy_argparse 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。

捐赠

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

联系方式

微信: yuyangiit
邮箱: yuyangit.0515@qq.com

Release files for xy-argparse 1.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xy-argparse 1.0.12
File Size Uploaded
xy_argparse-1.0.12.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xy-argparse 1.0.12
File Interpreter ABI Platform
xy_argparse-1.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / xy_argparse-1.0.12.tar.gz

Download URL xy_argparse-1.0.12.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c7c22a1fe5feb5e20a3790bd0f4559b7c7a721b865cd2fb10a418ae1304e502c
BLAKE2b-256 checksum
How to use checksums
d8b1afd4e3db97ff775d40e4ff7a3046a67646b420d9ceac87cee78198002782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / xy_argparse-1.0.12-py3-none-any.whl

Download URL xy_argparse-1.0.12-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc1560d481c0ab739ce318fa9ddda3515519da3eb36865cc436556cff5fd5770
BLAKE2b-256 checksum
How to use checksums
0c86becc5a9ca365c5a17ed19d7813109f1fa67eadc1a101a9fcfc1948b1a36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.12 This release

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page