12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/04/09 12:56:07
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : client enter point
- if run :
- fgh git clone https://github.com/xx/yy.git
- then run :
- git clone https://user:your_token@{HOST}/https://github.com/your_name/your_private_repo
- command:
- clone, push, pull, commit, add, status, log, diff, branch, checkout, merge, rebase, reset, tag, fetch, remote, init, config, help
- all change it to git command.
- if run:
- fgh wget https://xx.com/yy.zip
- then run:
- wget https://xx.com/yy.zip
- if run:
- fgh curl -O https://{HOST}/https://xx.com/yy.zip
- then run:
- curl -O https://{HOST}/https://xx.com/yy.zip
- """
- import os,sys,re
- import argparse
- class Client:
- def __init__(self):
- self.read_config()
- self.args = Client.parse_args()
- def read_config(self):
- import dotenv
- dotenv.load_dotenv()
- fgit_host = os.getenv('FGIT_HOST')
- token = os.getenv('FGIT_TOKEN')
- @staticmethod
- def parse_args(cls):
- parser = argparse.ArgumentParser(description='fgit client')
- parser.add_argument('command', type=str, help='fgit command',
- choices=['clone', 'push', 'pull', 'commit', 'add', 'status', 'log', 'diff', 'branch', 'checkout', 'merge', 'rebase', 'reset', 'tag', 'fetch', 'remote', 'init', 'config', 'help'])
- parser.add_argument('args', type=str, nargs='*', help='fgit command args')
- return parser.parse_args()
- def choose_host(self):
- """choose host"""
- pass
- def run(self):
- args = self.parse_args()
- command = args.command
- if len(args.args) == 0 and command != 'help':
- print('Usage: fgit <command> [<args>]')
- sys.exit(1)
- if command == 'help':
- print('Usage: fgit <command> [<args>]')
- print('Commands:')
- print(' clone Clone a repository into a new directory')
- print(' push Update remote refs along with associated objects')
- print(' pull Fetch from and integrate with another repository or a local branch')
- print(' commit Record changes to the repository')
- print(' add Add file contents to the index')
- print(' status Show the working tree status')
- print(' log Show commit logs')
- print(' diff Show changes between commits, commit and working tree, etc')
- print(' branch List, create, or delete branches')
- print(' checkout Switch branches or restore working tree files')
- print(' merge Join two or more development histories together')
- print(' rebase Reapply commits on top of another base tip')
- print(' reset Reset current HEAD to the specified state')
- print(' tag Create, list, delete or verify a tag object signed with GPG')
- print(' fetch Download objects and refs from another repository')
- print(' remote Manage set of tracked repositories')
- print(' init Create an empty Git repository or reinitialize an existing one')
- print(' config Get and set repository or global options')
- print(' help Show help')
- sys.exit(0)
- if not re.match(r'^https://github.com', args.args[0]):
- print('Invalid repo url, only support github.com, for example: https://github.com/xx/yy.git')
- sys.exit(1)
- os.system('git ' + command + ' https://{user}:{your_token}@ghproxy.org/' + ' '.join(args.args))
- if __name__=='__main__':
- client = Client()
- client.run()
|