(CommandList
  children: [
    (C {(set)} {(-euo)} {(pipefail)})
    (FuncDef
      name: error
      body: 
        (BraceGroup
          children: [
            (If
              arms: [
                (if_arm
                  cond: [
                    (Sentence
                      child: 
                        (C {(Lit_Other '[')} {($ VSub_Pound '$#')} {(KW_Bang '!') (Lit_Other '=')} {(0)} 
                          {(Lit_Other ']')}
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [
                    (SimpleCommand
                      words: [{(echo)} {(-en)} {(SQ <'\\e[0;31m'>)}]
                      redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[82])]
                    )
                    (Pipeline
                      children: [
                        (C {(echo)} {(DQ ($ VSub_At '$@'))})
                        (Subshell
                          child: (AndOr children:[(C {(fold)} {(-s)}) (C {(cat)})] op_id:Op_DPipe)
                          redirects: [
                            (Redir
                              op_id: Redir_GreatAnd
                              fd: 16777215
                              arg_word: {(2)}
                              spids: [104]
                            )
                          ]
                          spids: [94 102]
                        )
                      ]
                      negated: False
                    )
                    (SimpleCommand
                      words: [{(echo)} {(-en)} {(SQ <'\\e[0m'>)}]
                      redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[116])]
                    )
                  ]
                  spids: [16777215 71]
                )
              ]
              spids: [16777215 120]
            )
          ]
          spids: [54]
        )
      spids: [50 53]
    )
    (FuncDef
      name: fail
      body: 
        (BraceGroup
          children: [
            (C {(error)} {(DQ ($ VSub_At '$@'))})
            (SimpleCommand
              words: [{(echo)} {(DQ ('*** DOCS GENERATION FAILED ***'))}]
              redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[145])]
            )
            (C {(exit)} {(1)})
          ]
          spids: [129]
        )
      spids: [125 128]
    )
    (FuncDef
      name: assert_dependencies
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (SimpleCommand
                  words: [{(which)} {(mkdocs)}]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 16777215
                      arg_word: {(/dev/null)}
                      spids: [172]
                    )
                  ]
                )
                (C {(fail)} {(DQ ('You must install mkdocs before using this script.'))})
              ]
              op_id: Op_DPipe
            )
          ]
          spids: [165]
        )
      spids: [161 164]
    )
    (FuncDef
      name: handle_args
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:PUSH_AFTER_GENERATE)
                  op: Equal
                  rhs: {(DQ (no))}
                  spids: [197]
                )
              ]
              spids: [197]
            )
            (While
              cond: [(Sentence child:(C {(getopts)} {(DQ ('d:p'))} {(opt)}) terminator:<Op_Semi ';'>)]
              body: 
                (DoGroup
                  children: [
                    (Case
                      to_match: {($ VSub_Name '$opt')}
                      arms: [
                        (case_arm
                          pat_list: [{(d)}]
                          action: [
                            (Assignment
                              keyword: Assign_None
                              pairs: [
                                (assign_pair
                                  lhs: (LhsName name:OUTPUT_DIR)
                                  op: Equal
                                  rhs: {(DQ ($ VSub_Name '$OPTARG'))}
                                  spids: [229]
                                )
                              ]
                              spids: [229]
                            )
                          ]
                          spids: [225 226 235 16777215]
                        )
                        (case_arm
                          pat_list: [{(p)}]
                          action: [
                            (Assignment
                              keyword: Assign_None
                              pairs: [
                                (assign_pair
                                  lhs: (LhsName name:PUSH_AFTER_GENERATE)
                                  op: Equal
                                  rhs: {(DQ (yes))}
                                  spids: [242]
                                )
                              ]
                              spids: [242]
                            )
                          ]
                          spids: [238 239 248 16777215]
                        )
                        (case_arm
                          pat_list: [{(Lit_Other '*')}]
                          action: [(C {(usage)})]
                          spids: [251 252 258 16777215]
                        )
                      ]
                      spids: [218 222 261]
                    )
                  ]
                  spids: [215 264]
                )
            )
            (If
              arms: [
                (if_arm
                  cond: [
                    (Sentence
                      child: 
                        (C {(Lit_Other '[')} {(-z)} 
                          {
                            (DQ 
                              (BracedVarSub
                                token: <VSub_Name OUTPUT_DIR>
                                suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )})
                                spids: [287 290]
                              )
                            )
                          } {(Lit_Other ']')}
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:OUTPUT_DIR)
                          op: Equal
                          rhs: 
                            {
                              (DQ 
                                (CommandSubPart
                                  command_list: 
                                    (CommandList
                                      children: [
                                        (C {(mktemp)} {(-d)} 
                                          {
                                            (DQ 
                                              (BracedVarSub
                                                token: <VSub_Name TMPDIR>
                                                suffix_op: 
                                                  (StringUnary
                                                    op_id: VTest_ColonHyphen
                                                    arg_word: {(Lit_Slash /) (tmp)}
                                                  )
                                                spids: [308 313]
                                              ) (/docs-) 
                                              (CommandSubPart
                                                command_list: 
                                                  (CommandList
                                                    children: [(C {(date)} {(-I)})]
                                                  )
                                                left_token: <Left_CommandSub '$('>
                                                spids: [315 319]
                                              ) (.XXXXXXXXXX)
                                            )
                                          }
                                        )
                                      ]
                                    )
                                  left_token: <Left_CommandSub '$('>
                                  spids: [302 322]
                                )
                              )
                            }
                          spids: [300]
                        )
                      ]
                      spids: [300]
                    )
                    (C {(echo)} {(DQ ('Generating docs in ') ($ VSub_Name '$OUTPUT_DIR'))})
                  ]
                  spids: [16777215 297]
                )
              ]
              spids: [16777215 334]
            )
          ]
          spids: [190]
        )
      spids: [186 189]
    )
    (FuncDef
      name: usage
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [
                {(echo)}
                {(DQ ('Generate (and optionally push to git) documentation for Sandstorm.'))}
              ]
              redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[352])]
            )
            (SimpleCommand
              words: [{(echo)} {(DQ )}]
              redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[361])]
            )
            (SimpleCommand
              words: [{(echo)} {(DQ ('usage: ') ($ VSub_Number '$0') (' [-d directoryname] [-p]'))}]
              redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[373])]
            )
            (C {(echo)} 
              {
                (SQ 
                  <
'If -d and argument is specified, generate the docs to that directory. Else, use a directory with random name.'
                  >
                )
              }
            )
            (SimpleCommand
              words: [
                {(echo)}
                {
                  (SQ 
                    <
'If -p is specified, run "git push" from that directory once generation is complete.'
                    >
                  )
                }
              ]
              redirects: [(Redir op_id:Redir_GreatAnd fd:16777215 arg_word:{(2)} spids:[390])]
            )
            (C {(exit)} {(1)})
          ]
          spids: [343]
        )
      spids: [339 342]
    )
    (FuncDef
      name: create_index_page
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(echo)} {(SQ <'<META http-equiv="refresh" content="0;URL=/en/latest/">'>)}]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: 16777215
                  arg_word: {(DQ ($ VSub_Name '$OUTPUT_DIR') (/index.html))}
                  spids: [426]
                )
              ]
            )
          ]
          spids: [405]
        )
      spids: [401 404]
    )
    (FuncDef
      name: run_mkdocs_build
      body: 
        (BraceGroup
          children: [
            (C {(rm)} {(-rf)} {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest))})
            (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/))})
            (C {(mkdocs)} {(build)} {(--site-dir)} {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/))})
            (C {(rm)} {(-rf)} {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/env))})
            (C {(rm)} {(-rf)} {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/__init__.py))} 
              {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/__init__.pyc))}
            )
          ]
          spids: [440]
        )
      spids: [436 439]
    )
    (FuncDef
      name: git_push_if_desired
      body: 
        (BraceGroup
          children: [
            (If
              arms: [
                (if_arm
                  cond: [
                    (Sentence
                      child: 
                        (C {(Lit_Other '[')} {(DQ (${ VSub_Name PUSH_AFTER_GENERATE))} 
                          {(KW_Bang '!') (Lit_Other '=')} {(DQ (yes))} {(Lit_Other ']')}
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [(ControlFlow token:<ControlFlow_Return return>)]
                  spids: [16777215 538]
                )
              ]
              spids: [16777215 544]
            )
            (SimpleCommand
              words: [{(pushd)} {(DQ ($ VSub_Name '$OUTPUT_DIR'))}]
              redirects: [(Redir op_id:Redir_Great fd:16777215 arg_word:{(/dev/null)} spids:[554])]
            )
            (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 ') 
                  (CommandSubPart
                    command_list: (CommandList children:[(C {(date)} {(-R)})])
                    left_token: <Left_CommandSub '$('>
                    spids: [594 598]
                  )
                )
              }
            )
            (C {(git)} {(push)})
            (SimpleCommand
              words: [{(popd)}]
              redirects: [(Redir op_id:Redir_Great fd:16777215 arg_word:{(/dev/null)} spids:[609])]
            )
          ]
          spids: [514]
        )
      spids: [510 513]
    )
    (FuncDef
      name: generate_redirect_to
      body: 
        (BraceGroup
          children: [
            (C {(echo)} 
              {
                (DQ ("<html><head><meta http-equiv='refresh' content='0;url=") ($ VSub_Number '$1') 
                  ("'><link rel='canonical' href='") ($ VSub_Number '$1') ("'><script type='text/javascript'>window.location.replace('") 
                  ($ VSub_Number '$1') ("' + window.location.hash);</script></head><body><p>Moved to: <a href='") ($ VSub_Number '$1') ("'>") 
                  ($ VSub_Number '$1') ("</a><br>(Sandstorm Web Publishing doesn't support 301 redirects :(.)</body></html>")
                )
              }
            )
          ]
          spids: [620]
        )
      spids: [616 619]
    )
    (FuncDef
      name: add_redirect_hacks
      body: 
        (BraceGroup
          children: [
            (C {(mkdir)} {(-p)} 
              {(DQ ($ VSub_Name '$OUTPUT_DIR') (/en/latest/developing/security-practices))}
            )
            (SimpleCommand
              words: [
                {(generate_redirect_to)}
                {(DQ ('https://docs.sandstorm.io/en/latest/using/security-practices/'))}
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: 16777215
                  arg_word: 
                    {
                      (DQ ($ VSub_Name '$OUTPUT_DIR') 
                        (/en/latest/developing/security-practices/index.html)
                      )
                    }
                  spids: [669]
                )
              ]
            )
          ]
          spids: [646]
        )
      spids: [642 645]
    )
    (C {(assert_dependencies)})
    (C {(handle_args)} {(DQ ($ VSub_At '$@'))})
    (C {(create_index_page)})
    (C {(run_mkdocs_build)})
    (C {(add_redirect_hacks)})
    (C {(git_push_if_desired)})
  ]
)