コード例 #1
0
def pan_down(event):
    """ Pans the example pan down"""
    global _SECTION
    telemetry.track_key('ControlN')

    if _SECTION < 10:
        _SECTION += 1
コード例 #2
0
def pan_up(event):
    """ Pans the example pan up"""
    global _SECTION
    telemetry.track_key('ControlY')

    if _SECTION > 1:
        _SECTION -= 1
コード例 #3
0
ファイル: app.py プロジェクト: jaczhan/azure-cli
    def handle_scoping_input(self, continue_flag, cmd, text):
        default_split = text.partition(SELECT_SYMBOL['scope'])[2].split()
        cmd = cmd.replace(SELECT_SYMBOL['scope'], '')

        if text and SELECT_SYMBOL['scope'] == text[0:2]:
            continue_flag = True

            if not default_split:
                self.default_command = ""
                set_scope("", add=False)
                print('unscoping all')

                return continue_flag, cmd

            while default_split:
                if not text:
                    value = ''
                else:
                    value = default_split[0]

                if self.default_command:
                    tree_val = self.default_command + " " + value
                else:
                    tree_val = value

                if in_tree(self.completer.command_tree, tree_val.strip()):
                    self.set_scope(value)
                    print("defaulting: " + value)
                    cmd = cmd.replace(SELECT_SYMBOL['scope'], '')
                    telemetry.track_ssg('scope command', value)

                elif SELECT_SYMBOL['unscope'] == default_split[0] and \
                        len(self.default_command.split()) > 0:

                    value = self.default_command.split()[-1]
                    self.default_command = ' ' + ' '.join(
                        self.default_command.split()[:-1])

                    if not self.default_command.strip():
                        self.default_command = self.default_command.strip()
                    set_scope(self.default_command, add=False)
                    print('unscoping: ' + value)

                elif SELECT_SYMBOL['unscope'] not in text:
                    print("Scope must be a valid command")

                default_split = default_split[1:]
        else:
            return continue_flag, cmd
        return continue_flag, cmd
コード例 #4
0
ファイル: app.py プロジェクト: jaczhan/azure-cli
    def run(self):
        """ starts the REPL """
        telemetry.start()
        from azure.cli.core.application import APPLICATION
        APPLICATION.get_progress_controller = self.progress_patch

        from azclishell.configuration import SHELL_HELP
        self.cli.buffers['symbols'].reset(
            initial_document=Document(u'{}'.format(SHELL_HELP)))

        while True:
            try:
                try:
                    document = self.cli.run(reset_current_buffer=True)
                    text = document.text
                    if not text:  # not input
                        self.set_prompt()
                        continue
                    cmd = text
                    outside = False

                except AttributeError:  # when the user pressed Control D
                    break
                else:
                    b_flag, c_flag, outside, cmd = self._special_cases(
                        text, cmd, outside)

                    if b_flag:
                        break
                    if c_flag:
                        self.set_prompt()
                        continue

                    if not self.default_command:
                        self.history.append(text)

                    self.set_prompt()

                    if outside:
                        subprocess.Popen(cmd, shell=True).communicate()
                    else:
                        self.cli_execute(cmd)

            except KeyboardInterrupt:  # CTRL C
                self.set_prompt()
                continue

        print('Have a lovely day!!')
        telemetry.conclude()
コード例 #5
0
ファイル: app.py プロジェクト: jaczhan/azure-cli
    def _special_cases(self, text, cmd, outside):
        break_flag = False
        continue_flag = False

        if text and len(text.split()) > 0 and text.split()[0].lower() == 'az':
            telemetry.track_ssg('az', text)
            cmd = ' '.join(text.split()[1:])
        if self.default_command:
            cmd = self.default_command + " " + cmd

        if text.strip() == "quit" or text.strip() == "exit":
            break_flag = True
        elif text.strip(
        ) == "clear-history":  # clears the history, but only when you restart
            outside = True
            cmd = 'echo -n "" >' +\
                os.path.join(
                    SHELL_CONFIG_DIR(),
                    SHELL_CONFIGURATION.get_history())
        elif text.strip() == CLEAR_WORD:
            outside = True
            cmd = CLEAR_WORD
        if '--version' in text:
            try:
                continue_flag = True
                show_version_info_exit(sys.stdout)
            except SystemExit:
                pass
        if text:
            if text[0] == SELECT_SYMBOL['outside']:
                cmd = text[1:]
                outside = True
                if cmd.strip() and cmd.split()[0] == 'cd':
                    handle_cd(parse_quotes(cmd))
                    continue_flag = True
                telemetry.track_ssg('outside', '')

            elif text[0] == SELECT_SYMBOL['exit_code']:
                meaning = "Success" if self.last_exit == 0 else "Failure"

                print(meaning + ": " + str(self.last_exit))
                continue_flag = True
                telemetry.track_ssg('exit code', '')

            elif text[0] == SELECT_SYMBOL['query']:  # query previous output
                continue_flag = self.handle_jmespath_query(text, continue_flag)

            elif "|" in text or ">" in text:  # anything I don't parse, send off
                outside = True
                cmd = "az " + cmd

            elif SELECT_SYMBOL['example'] in text:
                cmd, continue_flag = self.handle_example(cmd, continue_flag)
                telemetry.track_ssg('tutorial', text)

        continue_flag, cmd = self.handle_scoping_input(continue_flag, cmd,
                                                       text)

        return break_flag, continue_flag, outside, cmd
コード例 #6
0
ファイル: app.py プロジェクト: jaczhan/azure-cli
 def handle_jmespath_query(self, text, continue_flag):
     if self.last and self.last.result:
         if hasattr(self.last.result, '__dict__'):
             input_dict = dict(self.last.result)
         else:
             input_dict = self.last.result
         try:
             query_text = text.partition(SELECT_SYMBOL['query'])[2]
             result = ""
             if query_text:
                 result = jmespath.search(query_text, input_dict)
             if isinstance(result, str):
                 print(result)
             else:
                 print(json.dumps(result, sort_keys=True, indent=2))
         except jmespath.exceptions.ParseError:
             print("Invalid Query")
     continue_flag = True
     telemetry.track_ssg('query', text)
     return continue_flag
コード例 #7
0
def config_settings(event):
    """ opens the configuration """
    global PROMPTING
    telemetry.track_key('F1')

    PROMPTING = True
    config = azclishell.configuration.CONFIGURATION
    answer = ""
    questions = {
        "Do you want command descriptions": "command_description",
        "Do you want parameter descriptions": "param_description",
        "Do you want examples": "examples"
    }
    for question in questions:
        while answer.lower() != 'y' and answer.lower() != 'n':
            answer = prompt(u'\n%s (y/n): ' % question)
        config.set_val('Layout', questions[question], format_response(answer))
        answer = ""

    PROMPTING = False
    print("\nPlease restart shell for changes to take effect.\n\n")
    event.cli.set_return_value(event.cli.current_buffer)
コード例 #8
0
def exit_(event):
    """ exits the program when Control D is pressed """
    telemetry.track_key('ControlD')
    event.cli.set_return_value(None)
コード例 #9
0
def toggle_symbols(event):
    """ shows the symbol bindings"""
    global SYMBOLS
    telemetry.track_key('F3')

    SYMBOLS = not SYMBOLS
コード例 #10
0
def toggle_default(event):
    """ shows the defaults"""
    global SHOW_DEFAULT
    telemetry.track_key('F2')

    SHOW_DEFAULT = not SHOW_DEFAULT