github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/cli/sawtooth_cli/parent_parsers.py (about) 1 # Copyright 2017 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the 'License'); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 from argparse import ArgumentParser 17 18 19 def base_http_parser(): 20 """Creates a parser with arguments specific to sending an HTTP request 21 to the REST API. 22 23 Returns: 24 {ArgumentParser}: Base parser with default HTTP args 25 """ 26 base_parser = ArgumentParser(add_help=False) 27 28 base_parser.add_argument( 29 '--url', 30 type=str, 31 help="identify the URL of the validator's REST API " 32 "(default: http://localhost:8008)") 33 base_parser.add_argument( 34 '-u', '--user', 35 type=str, 36 metavar='USERNAME[:PASSWORD]', 37 help='specify the user to authorize request') 38 39 return base_parser 40 41 42 def base_list_parser(): 43 """Creates a parser with arguments specific to formatting lists 44 of resources. 45 46 Returns: 47 {ArgumentParser}: Base parser with defaul list args 48 """ 49 base_parser = ArgumentParser(add_help=False) 50 51 base_parser.add_argument( 52 '-F', '--format', 53 action='store', 54 default='default', 55 choices=['csv', 'json', 'yaml', 'default'], 56 help='choose the output format') 57 58 return base_parser 59 60 61 def base_show_parser(): 62 """Creates a parser with arguments specific to formatting a 63 single resource. 64 65 Returns: 66 {ArgumentParser}: Base parser with default show args 67 """ 68 base_parser = ArgumentParser(add_help=False) 69 70 base_parser.add_argument( 71 '-k', '--key', 72 type=str, 73 help='show a single property from the block or header') 74 base_parser.add_argument( 75 '-F', '--format', 76 action='store', 77 default='yaml', 78 choices=['yaml', 'json'], 79 help='choose the output format (default: yaml)') 80 81 return base_parser