client.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/04/09 12:56:07
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : client enter point
  8. if run :
  9. fgh git clone https://github.com/xx/yy.git
  10. then run :
  11. git clone https://user:your_token@{HOST}/https://github.com/your_name/your_private_repo
  12. command:
  13. clone, push, pull, commit, add, status, log, diff, branch, checkout, merge, rebase, reset, tag, fetch, remote, init, config, help
  14. all change it to git command.
  15. if run:
  16. fgh wget https://xx.com/yy.zip
  17. then run:
  18. wget https://xx.com/yy.zip
  19. if run:
  20. fgh curl -O https://{HOST}/https://xx.com/yy.zip
  21. then run:
  22. curl -O https://{HOST}/https://xx.com/yy.zip
  23. """
  24. import os,sys,re
  25. import argparse
  26. class Client:
  27. def __init__(self):
  28. self.read_config()
  29. self.args = Client.parse_args()
  30. def read_config(self):
  31. import dotenv
  32. dotenv.load_dotenv()
  33. fgit_host = os.getenv('FGIT_HOST')
  34. token = os.getenv('FGIT_TOKEN')
  35. @staticmethod
  36. def parse_args(cls):
  37. parser = argparse.ArgumentParser(description='fgit client')
  38. parser.add_argument('command', type=str, help='fgit command',
  39. choices=['clone', 'push', 'pull', 'commit', 'add', 'status', 'log', 'diff', 'branch', 'checkout', 'merge', 'rebase', 'reset', 'tag', 'fetch', 'remote', 'init', 'config', 'help'])
  40. parser.add_argument('args', type=str, nargs='*', help='fgit command args')
  41. return parser.parse_args()
  42. def choose_host(self):
  43. """choose host"""
  44. pass
  45. def run(self):
  46. args = self.parse_args()
  47. command = args.command
  48. if len(args.args) == 0 and command != 'help':
  49. print('Usage: fgit <command> [<args>]')
  50. sys.exit(1)
  51. if command == 'help':
  52. print('Usage: fgit <command> [<args>]')
  53. print('Commands:')
  54. print(' clone Clone a repository into a new directory')
  55. print(' push Update remote refs along with associated objects')
  56. print(' pull Fetch from and integrate with another repository or a local branch')
  57. print(' commit Record changes to the repository')
  58. print(' add Add file contents to the index')
  59. print(' status Show the working tree status')
  60. print(' log Show commit logs')
  61. print(' diff Show changes between commits, commit and working tree, etc')
  62. print(' branch List, create, or delete branches')
  63. print(' checkout Switch branches or restore working tree files')
  64. print(' merge Join two or more development histories together')
  65. print(' rebase Reapply commits on top of another base tip')
  66. print(' reset Reset current HEAD to the specified state')
  67. print(' tag Create, list, delete or verify a tag object signed with GPG')
  68. print(' fetch Download objects and refs from another repository')
  69. print(' remote Manage set of tracked repositories')
  70. print(' init Create an empty Git repository or reinitialize an existing one')
  71. print(' config Get and set repository or global options')
  72. print(' help Show help')
  73. sys.exit(0)
  74. if not re.match(r'^https://github.com', args.args[0]):
  75. print('Invalid repo url, only support github.com, for example: https://github.com/xx/yy.git')
  76. sys.exit(1)
  77. os.system('git ' + command + ' https://{user}:{your_token}@ghproxy.org/' + ' '.join(args.args))
  78. if __name__=='__main__':
  79. client = Client()
  80. client.run()