forked from srsudar/eg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create eg_exec to allow invoking without pip
People installing with pip will have eg be global and available in all of their packages. This is easy, but some people might not like it. So, people can now run eg by running eg_exec.py.
- Loading branch information
Showing
3 changed files
with
120 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,7 @@ | ||
#!/usr/bin/python | ||
import argparse | ||
import sys | ||
|
||
from eg import eg_config | ||
from eg import eg_util | ||
from eg import eg_exec | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser( | ||
description='eg provides examples of common command usage.' | ||
) | ||
|
||
parser.add_argument( | ||
'-v', | ||
'--version', | ||
action='store_true', | ||
help='Display version information about eg' | ||
) | ||
|
||
parser.add_argument( | ||
'--config-file', | ||
help='Path to the .egrc file, if it is not in the default location.' | ||
) | ||
|
||
parser.add_argument( | ||
'--examples-dir', | ||
help='The location to the examples/ dir that ships with eg' | ||
) | ||
|
||
parser.add_argument( | ||
'--custom-dir', | ||
help='Path to a directory containing user-defined examples.' | ||
) | ||
|
||
parser.add_argument( | ||
'--list', | ||
action='store_true', | ||
help='Show all the programs with eg entries.' | ||
) | ||
|
||
parser.add_argument( | ||
'--color', | ||
action='store_true', | ||
dest='use_color', | ||
default=None, | ||
help='Colorize output.' | ||
) | ||
|
||
parser.add_argument( | ||
'--no-color', | ||
action='store_false', | ||
dest='use_color', | ||
help='Do not colorize output.' | ||
) | ||
|
||
parser.add_argument( | ||
'program', | ||
nargs='?', | ||
help='The program for which to display examples.' | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if len(sys.argv) < 2: | ||
parser.print_help() | ||
elif not args.version and not args.list and not args.program: | ||
print 'you must specify a program or pass the --list or --version flags' | ||
else: | ||
config = eg_config.get_resolved_config_items( | ||
egrc_path=args.config_file, | ||
examples_dir=args.examples_dir, | ||
custom_dir=args.custom_dir, | ||
use_color=args.use_color | ||
) | ||
|
||
if args.list: | ||
# Show what's available. | ||
supported_programs = eg_util.get_list_of_all_supported_commands( | ||
config | ||
) | ||
msg_line_1 = 'Legend: ' | ||
msg_line_2 = (' ' + | ||
eg_util.FLAG_ONLY_CUSTOM + | ||
' only custom files' | ||
) | ||
msg_line_3 = (' ' + | ||
eg_util.FLAG_CUSTOM_AND_DEFAULT + | ||
' custom and default files' | ||
) | ||
msg_line_4 = ' ' + ' only default files (no symbol)' | ||
msg_line_5 = '' | ||
msg_line_6 = 'Programs supported by eg: ' | ||
|
||
preamble = [ | ||
msg_line_1, | ||
msg_line_2, | ||
msg_line_3, | ||
msg_line_4, | ||
msg_line_5, | ||
msg_line_6 | ||
] | ||
|
||
for line in preamble: | ||
print line | ||
|
||
for program in supported_programs: | ||
print program | ||
elif args.version: | ||
print eg_util.VERSION | ||
else: | ||
eg_util.handle_program(args.program, config) | ||
eg_exec.run_eg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import argparse | ||
import eg_config | ||
import eg_util | ||
import sys | ||
|
||
|
||
def run_eg(): | ||
|
||
parser = argparse.ArgumentParser( | ||
description='eg provides examples of common command usage.' | ||
) | ||
|
||
parser.add_argument( | ||
'-v', | ||
'--version', | ||
action='store_true', | ||
help='Display version information about eg' | ||
) | ||
|
||
parser.add_argument( | ||
'--config-file', | ||
help='Path to the .egrc file, if it is not in the default location.' | ||
) | ||
|
||
parser.add_argument( | ||
'--examples-dir', | ||
help='The location to the examples/ dir that ships with eg' | ||
) | ||
|
||
parser.add_argument( | ||
'--custom-dir', | ||
help='Path to a directory containing user-defined examples.' | ||
) | ||
|
||
parser.add_argument( | ||
'--list', | ||
action='store_true', | ||
help='Show all the programs with eg entries.' | ||
) | ||
|
||
parser.add_argument( | ||
'--color', | ||
action='store_true', | ||
dest='use_color', | ||
default=None, | ||
help='Colorize output.' | ||
) | ||
|
||
parser.add_argument( | ||
'--no-color', | ||
action='store_false', | ||
dest='use_color', | ||
help='Do not colorize output.' | ||
) | ||
|
||
parser.add_argument( | ||
'program', | ||
nargs='?', | ||
help='The program for which to display examples.' | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if len(sys.argv) < 2: | ||
parser.print_help() | ||
elif not args.version and not args.list and not args.program: | ||
print 'you must specify a program or pass the --list or --version flags' | ||
else: | ||
config = eg_config.get_resolved_config_items( | ||
egrc_path=args.config_file, | ||
examples_dir=args.examples_dir, | ||
custom_dir=args.custom_dir, | ||
use_color=args.use_color | ||
) | ||
|
||
if args.list: | ||
# Show what's available. | ||
supported_programs = eg_util.get_list_of_all_supported_commands( | ||
config | ||
) | ||
msg_line_1 = 'Legend: ' | ||
msg_line_2 = (' ' + | ||
eg_util.FLAG_ONLY_CUSTOM + | ||
' only custom files' | ||
) | ||
msg_line_3 = (' ' + | ||
eg_util.FLAG_CUSTOM_AND_DEFAULT + | ||
' custom and default files' | ||
) | ||
msg_line_4 = ' ' + ' only default files (no symbol)' | ||
msg_line_5 = '' | ||
msg_line_6 = 'Programs supported by eg: ' | ||
|
||
preamble = [ | ||
msg_line_1, | ||
msg_line_2, | ||
msg_line_3, | ||
msg_line_4, | ||
msg_line_5, | ||
msg_line_6 | ||
] | ||
|
||
for line in preamble: | ||
print line | ||
|
||
for program in supported_programs: | ||
print program | ||
elif args.version: | ||
print eg_util.VERSION | ||
else: | ||
eg_util.handle_program(args.program, config) | ||
|
||
|
||
# We want people to be able to use eg without pip, by so we'll allow this to be | ||
# invoked directly. | ||
if __name__ == '__main__': | ||
run_eg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters