(command.CommandList
  children: [
    (C {<Id.KW_Set set>} {<-euo>} {<pipefail>})
    (command.ShFunction
      name: error
      body: 
        (BraceGroup
          children: [
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (C {<Id.Lit_LBracket '['>} {($ Id.VSub_Pound '$#')} 
                          {<Id.KW_Bang '!'> <Id.Lit_Equals '='>} {<0>} {<Id.Lit_RBracket ']'>}
                        )
                      terminator: <Id.Op_Semi _>
                    )
                  ]
                  action: [
                    (command.Simple
                      words: [{<echo>} {<-en>} {(SQ <'\\e[0;31m'>)}]
                      redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
                      do_fork: T
                    )
                    (command.Pipeline
                      children: [
                        (C {<echo>} {(DQ ($ Id.VSub_At '$@'))})
                        (command.Subshell
                          child: 
                            (command.AndOr
                              ops: [Id.Op_DPipe]
                              children: [(C {<fold>} {<-s>}) (C {<cat>})]
                            )
                          redirects: [
                            (redir
                              op: <Id.Redir_GreatAnd '>&'>
                              loc: (redir_loc.Fd fd:1)
                              arg: {<2>}
                            )
                          ]
                        )
                      ]
                      negated: F
                    )
                    (command.Simple
                      words: [{<echo>} {<-en>} {(SQ <'\\e[0m'>)}]
                      redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
                      do_fork: T
                    )
                  ]
                  spids: [57 71]
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: fail
      body: 
        (BraceGroup
          children: [
            (C {<error>} {(DQ ($ Id.VSub_At '$@'))})
            (command.Simple
              words: [{<echo>} {(DQ <'*** DOCS GENERATION FAILED ***'>)}]
              redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
              do_fork: T
            )
            (command.ControlFlow token:<Id.ControlFlow_Exit exit> arg_word:{<1>})
          ]
        )
    )
    (command.ShFunction
      name: assert_dependencies
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DPipe]
              children: [
                (command.Simple
                  words: [{<which>} {<mkdocs>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<'/dev/null'>}
                    )
                  ]
                  do_fork: T
                )
                (C {<fail>} {(DQ <'You must install mkdocs before using this script.'>)})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: handle_args
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:PUSH_AFTER_GENERATE)
                  op: assign_op.Equal
                  rhs: {(DQ <no>)}
                  spids: [197]
                )
              ]
            )
            (command.WhileUntil
              keyword: <Id.KW_While while>
              cond: [
                (command.Sentence
                  child: (C {<getopts>} {(DQ <'d:p'>)} {<opt>})
                  terminator: <Id.Op_Semi _>
                )
              ]
              body: 
                (command.DoGroup
                  children: [
                    (command.Case
                      to_match: {($ Id.VSub_DollarName '$opt')}
                      arms: [
                        (case_arm
                          pat_list: [{<d>}]
                          action: [
                            (command.ShAssignment
                              pairs: [
                                (assign_pair
                                  lhs: (sh_lhs_expr.Name name:OUTPUT_DIR)
                                  op: assign_op.Equal
                                  rhs: {(DQ ($ Id.VSub_DollarName '$OPTARG'))}
                                  spids: [229]
                                )
                              ]
                            )
                          ]
                          spids: [225 226 235 -1]
                        )
                        (case_arm
                          pat_list: [{<p>}]
                          action: [
                            (command.ShAssignment
                              pairs: [
                                (assign_pair
                                  lhs: (sh_lhs_expr.Name name:PUSH_AFTER_GENERATE)
                                  op: assign_op.Equal
                                  rhs: {(DQ <yes>)}
                                  spids: [242]
                                )
                              ]
                            )
                          ]
                          spids: [238 239 248 -1]
                        )
                        (case_arm
                          pat_list: [{<Id.Lit_Star '*'>}]
                          action: [(C {<usage>})]
                          spids: [251 252 258 -1]
                        )
                      ]
                    )
                  ]
                )
            )
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (C {<Id.Lit_LBracket '['>} {<-z>} 
                          {
                            (DQ 
                              (braced_var_sub
                                token: <Id.VSub_Name OUTPUT_DIR>
                                suffix_op: (suffix_op.Unary op_id:Id.VTest_ColonHyphen arg_word:(word.Empty))
                              )
                            )
                          } {<Id.Lit_RBracket ']'>}
                        )
                      terminator: <Id.Op_Semi _>
                    )
                  ]
                  action: [
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:OUTPUT_DIR)
                          op: assign_op.Equal
                          rhs: 
                            {
                              (DQ 
                                (command_sub
                                  left_token: <Id.Left_DollarParen '$('>
                                  child: 
                                    (C {<mktemp>} {<-d>} 
                                      {
                                        (DQ 
                                          (braced_var_sub
                                            token: <Id.VSub_Name TMPDIR>
                                            suffix_op: 
                                              (suffix_op.Unary
                                                op_id: Id.VTest_ColonHyphen
                                                arg_word: {<Id.Lit_Slash '/'> <tmp>}
                                              )
                                          ) <'/docs-'> (command_sub left_token:<Id.Left_DollarParen '$('> child:(C {<date>} {<-I>})) <.XXXXXXXXXX>
                                        )
                                      }
                                    )
                                )
                              )
                            }
                          spids: [300]
                        )
                      ]
                    )
                    (C {<echo>} {(DQ <'Generating docs in '> ($ Id.VSub_DollarName '$OUTPUT_DIR'))})
                  ]
                  spids: [280 297]
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: usage
      body: 
        (BraceGroup
          children: [
            (command.Simple
              words: [
                {<echo>}
                {(DQ <'Generate (and optionally push to git) documentation for Sandstorm.'>)}
              ]
              redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
              do_fork: T
            )
            (command.Simple
              words: [{<echo>} {(DQ )}]
              redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
              do_fork: T
            )
            (command.Simple
              words: [{<echo>} {(DQ <'usage: '> ($ Id.VSub_Number '$0') <' [-d directoryname] [-p]'>)}]
              redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
              do_fork: T
            )
            (C {<echo>} 
              {
                (SQ 
                  <
'If -d and argument is specified, generate the docs to that directory. Else, use a directory with random name.'
                  >
                )
              }
            )
            (command.Simple
              words: [
                {<echo>}
                {
                  (SQ 
                    <
'If -p is specified, run "git push" from that directory once generation is complete.'
                    >
                  )
                }
              ]
              redirects: [(redir op:<Id.Redir_GreatAnd '>&'> loc:(redir_loc.Fd fd:1) arg:{<2>})]
              do_fork: T
            )
            (command.ControlFlow token:<Id.ControlFlow_Exit exit> arg_word:{<1>})
          ]
        )
    )
    (command.ShFunction
      name: create_index_page
      body: 
        (BraceGroup
          children: [
            (command.Simple
              words: [{<echo>} {(SQ <'<META http-equiv="refresh" content="0;URL=/en/latest/">'>)}]
              redirects: [
                (redir
                  op: <Id.Redir_Great '>'>
                  loc: (redir_loc.Fd fd:1)
                  arg: {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/index.html'>)}
                )
              ]
              do_fork: T
            )
          ]
        )
    )
    (command.ShFunction
      name: run_mkdocs_build
      body: 
        (BraceGroup
          children: [
            (C {<rm>} {<-rf>} {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest'>)})
            (C {<mkdir>} {<-p>} {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/'>)})
            (C {<mkdocs>} {<build>} {<--site-dir>} 
              {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/'>)}
            )
            (C {<rm>} {<-rf>} {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/env'>)})
            (C {<rm>} {<-rf>} {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/__init__.py'>)} 
              {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/__init__.pyc'>)}
            )
          ]
        )
    )
    (command.ShFunction
      name: git_push_if_desired
      body: 
        (BraceGroup
          children: [
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (C {<Id.Lit_LBracket '['>} {(DQ (${ Id.VSub_Name PUSH_AFTER_GENERATE))} 
                          {<Id.KW_Bang '!'> <Id.Lit_Equals '='>} {(DQ <yes>)} {<Id.Lit_RBracket ']'>}
                        )
                      terminator: <Id.Op_Semi _>
                    )
                  ]
                  action: [(command.ControlFlow token:<Id.ControlFlow_Return return>)]
                  spids: [517 538]
                )
              ]
            )
            (command.Simple
              words: [{<pushd>} {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR'))}]
              redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<'/dev/null'>})]
              do_fork: T
            )
            (C {<git>} {<rm>} {<--ignore-unmatch>} {<--cached>} {(SQ <'en/latest/*'>)})
            (C {<git>} {<add>} {<'en/latest'>})
            (C {<git>} {<add>} {<index.html>})
            (C {<git>} {<commit>} {<-m>} 
              {
                (DQ <'Autocommit on '> 
                  (command_sub
                    left_token: <Id.Left_DollarParen '$('>
                    child: (C {<date>} {<-R>})
                  )
                )
              }
            )
            (C {<git>} {<push>})
            (command.Simple
              words: [{<popd>}]
              redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<'/dev/null'>})]
              do_fork: T
            )
          ]
        )
    )
    (command.ShFunction
      name: generate_redirect_to
      body: 
        (BraceGroup
          children: [
            (C {<echo>} 
              {
                (DQ <'<html><head><meta http-equiv=\'refresh\' content=\'0;url='> 
                  ($ Id.VSub_Number '$1') <'\'><link rel=\'canonical\' href=\''> ($ Id.VSub_Number '$1') 
                  <'\'><script type=\'text/javascript\'>window.location.replace(\''> ($ Id.VSub_Number '$1') <'\' + window.location.hash);</script></head><body><p>Moved to: <a href=\''> 
                  ($ Id.VSub_Number '$1') <'\'>'> ($ Id.VSub_Number '$1') 
                  <
'</a><br>(Sandstorm Web Publishing doesn\'t support 301 redirects :(.)</body></html>'
                  >
                )
              }
            )
          ]
        )
    )
    (command.ShFunction
      name: add_redirect_hacks
      body: 
        (BraceGroup
          children: [
            (C {<mkdir>} {<-p>} 
              {(DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') <'/en/latest/developing/security-practices'>)}
            )
            (command.Simple
              words: [
                {<generate_redirect_to>}
                {(DQ <'https://docs.sandstorm.io/en/latest/using/security-practices/'>)}
              ]
              redirects: [
                (redir
                  op: <Id.Redir_Great '>'>
                  loc: (redir_loc.Fd fd:1)
                  arg: 
                    {
                      (DQ ($ Id.VSub_DollarName '$OUTPUT_DIR') 
                        <'/en/latest/developing/security-practices/index.html'>
                      )
                    }
                )
              ]
              do_fork: T
            )
          ]
        )
    )
    (C {<assert_dependencies>})
    (C {<handle_args>} {(DQ ($ Id.VSub_At '$@'))})
    (C {<create_index_page>})
    (C {<run_mkdocs_build>})
    (C {<add_redirect_hacks>})
    (C {<git_push_if_desired>})
  ]
)