Skip to content

Commit

Permalink
gopinath-langote#96 Preliminary command completion
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeshAtole committed Jul 6, 2019
1 parent da89642 commit 750b0b1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions onebuild/1build_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash
_1build_completions()
{
COMPREPLY=($(compgen -W "$(1build -lr | sed 's/\\t//')" -- "${COMP_WORDS[COMP_CWORD]}"))
}

complete -F _1build_completions 1build
2 changes: 2 additions & 0 deletions onebuild/action_to_command_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from onebuild.help_command import HelpCommand
from onebuild.init_command import InitCommand
from onebuild.list_command import ListCommand
from onebuild.list_raw_command import ListRawCommand
from onebuild.perform_command import PerformCommand
from onebuild.version_command import VersionCommand

Expand All @@ -13,6 +14,7 @@ def __init__(self):
PredefinedActions.HELP: HelpCommand(),
PredefinedActions.INIT: InitCommand(),
PredefinedActions.LIST: ListCommand(),
PredefinedActions.LIST_RAW: ListRawCommand(),
PredefinedActions.VERSION: VersionCommand(),
PredefinedActions.PERFORM: PerformCommand()
})
Expand Down
8 changes: 8 additions & 0 deletions onebuild/input_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def argument_parser():
default=False,
help="Show all available commands - from `1build.yaml` file"
)
parser.add_argument(
'-lr', '--listraw',
action='store_true',
default=False,
help="Show all available command names - from `1build.yaml` file"
)
parser.add_argument(
'-v', '--version',
dest='version',
Expand All @@ -50,6 +56,8 @@ def command_to_run(arg_parser, arguments):
return PredefinedActions.INIT
if args.list:
return PredefinedActions.LIST
if args.listraw:
return PredefinedActions.LIST_RAW
if len(args.command) == 0:
return PredefinedActions.HELP

Expand Down
10 changes: 10 additions & 0 deletions onebuild/list_raw_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from onebuild.command import Command
from onebuild.config_parser import parse_project_config
from onebuild.utils import config_string


class ListRawCommand(Command):

def execute(self, arg_parser, arguments, build_file_name, command_name):
project = parse_project_config(build_file_name)
print(project.get_command_names())
1 change: 1 addition & 0 deletions onebuild/predefined_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class PredefinedActions:
VERSION = "ONEBUILD_VERSION"
HELP = "ONEBUILD_HELP"
LIST = "ONEBUILD_LIST"
LIST_RAW = "ONEBUILD_LIST_RAW"
INIT = "ONEBUILD_INIT"
PERFORM = "ONEBUILD_PERFROM"
3 changes: 3 additions & 0 deletions onebuild/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def available_commands(self):
def __str__(self):
return "project: " + self.name + "\ncommands:\n" + \
self.available_commands()

def get_command_names(self):
return "\n".join(map(lambda command: command.name, self.commands))

0 comments on commit 750b0b1

Please sign in to comment.