
    y                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 d	Z
d
ZddZdZddZ G d dej                        Zy)zIA command that lists all possible gcloud commands, optionally with flags.    )absolute_import)division)unicode_literalsN)base)cli_tree)walker_util_flags__name_c                     fdg } || g        |st         j                  }|j                  dj                  t	        |            dz          y)zDisplays the commands in the command tree in sorted order on out.

  Args:
    command: dict, The tree (nested dict) of command/group names.
    out: stream, The output stream, sys.stdout if None.
  c           	      8   ||t            gz   }| r!| j                  dj                  |             n7| j                  dj                  ||j                  t        g       z                t
        j                  |v rk|t
        j                     D ]U  }|j                  t         |      }|j                  t        g       }| j                  dj                  ||gz   |z                W t
        j                  |v r#|t
        j                     D ]  } | ||        yy)a!  Visit each command and group in the CLI command tree.

    Each command line is added to the commands list.

    Args:
      commands: [str], The list of command strings.
      command: dict, The tree (nested dict) of command/group names.
      args: [str], The subcommand arg prefix.
     N)_LOOKUP_INTERNAL_NAMEappendjoinget_LOOKUP_INTERNAL_FLAGSr   LOOKUP_COMMANDSLOOKUP_GROUPS)	commandscommandargs	args_nextcnameflagsgWalkCommandTrees	           !lib/surface/meta/list_commands.pyr   z4DisplayFlattenedCommandTree.<locals>.WalkCommandTree)   s      5677Ioochhy)* oochh
gkk"8"=
=? @7*x//0!uu*A.,b1dV!3e!;<= 1 (x--.!!Y/ / )    
N)sysstdoutwriter   sorted)r   outr   r   s      @r   DisplayFlattenedCommandTreer&   !   sF    04 ((GR(	
**C))DIIfX&'$./r   _SC_c                 T    d fdst         j                   | g        y)aT  Displays the static tab completion data on out.

  The static completion data is a shell script containing variable definitons
  of the form {_COMPLETIONS_PREFIX}{COMMAND.PATH} for each dotted command path.

  Args:
    command: dict, The tree (nested dict) of command/group names.
    out: stream, The output stream, sys.stdout if None.
  c                 R    t         dj                  |       j                  dd      z   S )N__-_)_COMPLETIONS_PREFIXr   replace)paths    r   ConvertPathToIdentifierz3DisplayCompletions.<locals>.ConvertPathToIdentifierX   s"    4!8!8c!BBBr   c           	         | j                  t              }||gz   }| j                  t        j                  g       }| j                  t        j                  g       }g }||z   D ]'  }|j                  |j                  t        |             ) |r0| j                  t        g       }|r;j                  dj                   
|      dj                  ||z                      noj                  dj                   
dg      dj                  |                   j                  dj                   
|      dj                  |                   |D ]i  }|j                  t        |      }|j                  t        g       }j                  dj                   
||gz         dj                  |                   k |D ]  }	 |	|        y)zVisit each command and group in the CLI command tree.

    Args:
      command: dict, The tree (nested dict) of command/group names.
      prefix: [str], The subcommand arg prefix.
    z{identifier}=({args})
r   )
identifierr   z-GCLOUD-WIDE-FLAGS-N)
r   r   r   r   r   r   r   r#   formatr   )r   prefixr   r   r   groupsnamesr   r   r   r0   r   r%   s             r   r   z+DisplayCompletions.<locals>.WalkCommandTree[   s    ;;,-DTF?D{{833R8H[[//4FEll155.23 kk0"5e			+22.t4%%-( 3 * 	+ 			+22.0E/FG% 3 " 	# 			+22.t4% 3 " 	# !uu*A.,b1		+22.ttf}=% 3 " 	#  a r   N)r!   r"   )r   r%   r0   r   s    `@@r   DisplayCompletionsr7   M   s'    C"H 

**C'2r   c                   ,    e Zd ZdZed        Zd Zd Zy)ListCommandsz2List all possible gcloud commands excluding flags.c                    | j                  dddt        z   dz          | j                  ddd       | j                  ddd	       | j                  d
dd       | j                  dddd       | j                  dddd       y )Nz--completions
store_truez              Write the static TAB completion data on the standard output. The
              data is a shell script containing variable definitons of the
              form ```z/{COMMAND.PATH}``` for each dotted command path.)actionhelpz--flagsz4Include the non-global flags for each command/group.z--flag-valuesz        Include the non-global flags and flag values/types for each
        command/group. Flags with fixed choice values will be listed as
        --flag=choice1,..., and flags with typed values will be listed
        as --flag=:type:.z--hiddenz#Include hidden commands and groups.z--universe-compatible-commandsTz.Exclusively show universe compatible commands.)hiddenr<   r=   restrictzCOMMAND/GROUP*z^Restrict the listing to these dotted command paths. For example: gcloud.alpha gcloud.beta.test)metavarnargsr=   )add_argumentr-   )parsers    r   ArgszListCommands.Args   s    
 "	"
 @@  	 C  E    2  4 (=	  ?
 ;	  =r   c                    |j                   rd|_        d|_        d|_        d|_        t        j                  | j                  |j                  |j                        j                  |j                  |j                  |j                        S )NTF)
with_flagswith_flag_values)
completionsr   flag_valuesr>   universe_compatible_commandsr   CommandTreeGenerator_cli_power_users_onlyWalkr?   )selfr   s     r   RunzListCommands.Run   st    djddk*/d'++""::)) d4;;994==I	Jr   c                 F    |j                   rt        |      S t        |      S N)rI   r7   r&   )rO   r   results      r   DisplayzListCommands.Display   s!    ''&v..r   N)__name__
__module____qualname____doc__staticmethodrE   rP   rT    r   r   r9   r9      s#    :%= %=N
J/r   r9   rR   )rX   
__future__r   r   r   r!   googlecloudsdk.callioper   r   r   r   r   r&   r-   r7   Commandr9   rZ   r   r   <module>r^      sR     P &  ' 
 ( , / #   &0R  4n:/4<< :/r   