Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
c877be78
Commit
c877be78
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a8eaf5c5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
main_parser.py
stbi/Lib/site-packages/pip/_internal/cli/main_parser.py
+99
-0
No files found.
stbi/Lib/site-packages/pip/_internal/cli/main_parser.py
0 → 100644
View file @
c877be78
"""A single place for constructing and exposing the main parser
"""
import
os
import
sys
from
pip._internal.cli
import
cmdoptions
from
pip._internal.cli.parser
import
(
ConfigOptionParser
,
UpdatingDefaultsHelpFormatter
,
)
from
pip._internal.commands
import
commands_dict
,
get_similar_commands
from
pip._internal.exceptions
import
CommandError
from
pip._internal.utils.misc
import
get_pip_version
,
get_prog
from
pip._internal.utils.typing
import
MYPY_CHECK_RUNNING
if
MYPY_CHECK_RUNNING
:
from
typing
import
Tuple
,
List
__all__
=
[
"create_main_parser"
,
"parse_command"
]
def
create_main_parser
():
# type: () -> ConfigOptionParser
"""Creates and returns the main parser for pip's CLI
"""
parser_kw
=
{
'usage'
:
'
\n
%
prog <command> [options]'
,
'add_help_option'
:
False
,
'formatter'
:
UpdatingDefaultsHelpFormatter
(),
'name'
:
'global'
,
'prog'
:
get_prog
(),
}
parser
=
ConfigOptionParser
(
**
parser_kw
)
parser
.
disable_interspersed_args
()
parser
.
version
=
get_pip_version
()
# add the general options
gen_opts
=
cmdoptions
.
make_option_group
(
cmdoptions
.
general_group
,
parser
)
parser
.
add_option_group
(
gen_opts
)
# so the help formatter knows
parser
.
main
=
True
# type: ignore
# create command listing for description
description
=
[
''
]
+
[
'{name:27} {command_info.summary}'
.
format
(
**
locals
())
for
name
,
command_info
in
commands_dict
.
items
()
]
parser
.
description
=
'
\n
'
.
join
(
description
)
return
parser
def
parse_command
(
args
):
# type: (List[str]) -> Tuple[str, List[str]]
parser
=
create_main_parser
()
# Note: parser calls disable_interspersed_args(), so the result of this
# call is to split the initial args into the general options before the
# subcommand and everything else.
# For example:
# args: ['--timeout=5', 'install', '--user', 'INITools']
# general_options: ['--timeout==5']
# args_else: ['install', '--user', 'INITools']
general_options
,
args_else
=
parser
.
parse_args
(
args
)
# --version
if
general_options
.
version
:
sys
.
stdout
.
write
(
parser
.
version
)
# type: ignore
sys
.
stdout
.
write
(
os
.
linesep
)
sys
.
exit
()
# pip || pip help -> print_help()
if
not
args_else
or
(
args_else
[
0
]
==
'help'
and
len
(
args_else
)
==
1
):
parser
.
print_help
()
sys
.
exit
()
# the subcommand name
cmd_name
=
args_else
[
0
]
if
cmd_name
not
in
commands_dict
:
guess
=
get_similar_commands
(
cmd_name
)
msg
=
[
'unknown command "{}"'
.
format
(
cmd_name
)]
if
guess
:
msg
.
append
(
'maybe you meant "{}"'
.
format
(
guess
))
raise
CommandError
(
' - '
.
join
(
msg
))
# all the args without the subcommand
cmd_args
=
args
[:]
cmd_args
.
remove
(
cmd_name
)
return
cmd_name
,
cmd_args
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment