Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2128] feature: help for module commands #1156

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions framework/pym/play/commands/help.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Display help

import sys, os
import sys, os, re

COMMANDS = ['help']

Expand All @@ -15,15 +15,27 @@ def execute(**kargs):
play_env = kargs.get("env")
cmdloader = kargs.get("cmdloader")

if len(sys.argv) == 3:
cmd = sys.argv[2]
if len(args) == 1:
cmd = args[0]
help_file = os.path.join(play_env["basedir"], 'documentation', 'commands', 'cmd-%s.txt' % cmd)
if os.path.exists(help_file):
print open(help_file, 'r').read()
else:
print '~ Oops, command \'%s\' not found. Try just \'play help\' to list all commands.' % cmd
print '~'
sys.exit(-1)
exists = False
slugCmd = re.sub('[-\s]+', '-', re.sub('[^\w\s-]', '', cmd.encode('ascii', 'ignore')).strip().lower())
for module in app.modules():
help_file = os.path\
.join(module, 'documentation', 'commands',
'cmd-%s.txt'
% slugCmd)
exists = os.path.exists(help_file)
if exists:
print open(help_file, 'r').read()
break
if not exists:
print '~ Oops, command \'%s\' not found. Try just \'play help\' to list all commands.' % cmd
print '~'
sys.exit(-1)
else:
main_help(cmdloader.commands, play_env)

Expand Down Expand Up @@ -52,4 +64,21 @@ def main_help(commands, play_env):
print "~"

def isCore(mod, play_env):
return mod.__file__.find(play_env["basedir"]) == 0
path = os.path.realpath(mod.__file__)
directory = os.path.realpath(play_env["basedir"])

isCore = True
try:
relpath = os.path.relpath(path, directory)
if relpath.startswith(os.pardir):
isCore = False
else:
if relpath.startswith('modules'):
isCore = False
else:
isCore = mod.__file__.find(play_env["basedir"]) == 0
except ValueError:
isCore = False

return isCore

12 changes: 10 additions & 2 deletions play
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ try:
application_path = os.getcwd()
remaining_args = sys.argv[2:]
else:
application_path = os.path.normpath(os.path.abspath(sys.argv[2]))
remaining_args = sys.argv[3:]
if sys.argv[1].lower() == 'help':
application_path = os.path.normpath(os.path.abspath(sys.argv[2]))
exists = os.path.exists(application_path)
if exists:
remaining_args = sys.argv[3:]
else:
remaining_args = sys.argv[2:]
else:
application_path = os.path.normpath(os.path.abspath(sys.argv[2]))
remaining_args = sys.argv[3:]

ignoreMissing = False
if remaining_args.count('--force') == 1:
Expand Down