Skip to content

Commit

Permalink
Adding a root command
Browse files Browse the repository at this point in the history
  • Loading branch information
palikar committed Jun 17, 2020
1 parent 96ec9ea commit 67852ef
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
12 changes: 4 additions & 8 deletions code_manager/commands/find.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import logging
import sys
import os
import subprocess
import sys


from code_manager.core.configuration import ConfigurationAware
from code_manager.utils.logger import RED
from code_manager.utils.logger import RESET
from code_manager.utils.logger import CYAN


class FindCommand(ConfigurationAware):
class FindCommand():

name = 'find'

Expand All @@ -37,12 +34,11 @@ def execute(self, args, path):

for file_name in files:
if color:
sys.stdout.buffer.write(bytes(RED + self.pack + RESET + ':' , 'utf-8') + file_name + b'\n')
sys.stdout.buffer.write(bytes(RED + self.pack + RESET + ':', 'utf-8') + file_name + b'\n')
else:
sys.stdout.buffer.write(bytes(self.pack + ':', 'utf-8') + file_name + b'\n')

sys.stdout.buffer.flush()

sys.stdout.buffer.flush()

return 0

Expand Down
33 changes: 33 additions & 0 deletions code_manager/commands/root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys

from code_manager.core.configuration import ConfigurationAware
from code_manager.utils.logger import RED
from code_manager.utils.logger import RESET


class RootCommand(ConfigurationAware):

name = 'root'

def __init__(self):
self.color = False if self.opt.get('Commands', 'root-colors', fallback=True) == 'false' else True

def execute(self, args, path):

if self.color and not args.no_color:
color = True
elif args.no_color:
color = False

line = bytes(path, 'utf-8')
if color:
sys.stdout.buffer.write(bytes(RED + self.pack + RESET + ':', 'utf-8') + line + b'\n')
else:
sys.stdout.buffer.write(bytes(self.pack + ':', 'utf-8') + line + b'\n')

sys.stdout.buffer.flush()

return 0


ExportedClass = RootCommand
16 changes: 16 additions & 0 deletions code_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ def get_arg_parser():
)
find_parser.add_argument('rest', nargs=argparse.REMAINDER)

root_parser = subparsers.add_parser('root', help='Find the root directory of package')
root_parser.add_argument(
'-t', '--thing', action='store', default=None, dest='thing',
help='Group or package to execute the command for.',
)
root_parser.add_argument(
'-n', '--no-color', action='store_true', default=None, dest='no_color',
help='Supress any color in the output',
)
root_parser.add_argument('rest', nargs=argparse.REMAINDER)

return parser


Expand Down Expand Up @@ -569,6 +580,11 @@ def find(args, core):
core.run_command('find', args, thing=args.thing)


@command('root')
def root(args, core):
core.run_command('root', args, thing=args.thing)


@command('list-fetchers')
def list_fetchers(_, core):
print('Currently available fetchers:')
Expand Down

0 comments on commit 67852ef

Please sign in to comment.