loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor to use urfave/cli/v2 (#25959)

Replace #10912

And there are many new tests to cover the CLI behavior

There were some concerns about the "option order in hook scripts"
(https://github.com/go-gitea/gitea/pull/10912#issuecomment-1137543314),
it's not a problem now. Because the hook script uses `/gitea hook
--config=/app.ini pre-receive` format. The "config" is a global option,
it can appear anywhere.

----

## ⚠️ BREAKING ⚠️

This PR does it best to avoid breaking anything. The major changes are:

* `gitea` itself won't accept web's options: `--install-port` / `--pid`
/ `--port` / `--quiet` / `--verbose` .... They are `web` sub-command's
options.
* Use `./gitea web --pid ....` instead
* `./gitea` can still run the `web` sub-command as shorthand, with
default options
* The sub-command's options must follow the sub-command
* Before: `./gitea --sub-opt subcmd` might equal to `./gitea subcmd
--sub-opt` (well, might not ...)
* After: only `./gitea subcmd --sub-opt` could be used
* The global options like `--config` are not affected

authored by

wxiaoguang and committed by
GitHub
d0dbe52e 840830b6

+886 -643
+8 -3
assets/go-licenses.json
··· 985 985 "licenseText": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n\"License\" shall mean the terms and conditions for use, reproduction, and\ndistribution as defined by Sections 1 through 9 of this document.\n\n\"Licensor\" shall mean the copyright owner or entity authorized by the copyright\nowner that is granting the License.\n\n\"Legal Entity\" shall mean the union of the acting entity and all other entities\nthat control, are controlled by, or are under common control with that entity.\nFor the purposes of this definition, \"control\" means (i) the power, direct or\nindirect, to cause the direction or management of such entity, whether by\ncontract or otherwise, or (ii) ownership of fifty percent (50%) or more of the\noutstanding shares, or (iii) beneficial ownership of such entity.\n\n\"You\" (or \"Your\") shall mean an individual or Legal Entity exercising\npermissions granted by this License.\n\n\"Source\" form shall mean the preferred form for making modifications, including\nbut not limited to software source code, documentation source, and configuration\nfiles.\n\n\"Object\" form shall mean any form resulting from mechanical transformation or\ntranslation of a Source form, including but not limited to compiled object code,\ngenerated documentation, and conversions to other media types.\n\n\"Work\" shall mean the work of authorship, whether in Source or Object form, made\navailable under the License, as indicated by a copyright notice that is included\nin or attached to the work (an example is provided in the Appendix below).\n\n\"Derivative Works\" shall mean any work, whether in Source or Object form, that\nis based on (or derived from) the Work and for which the editorial revisions,\nannotations, elaborations, or other modifications represent, as a whole, an\noriginal work of authorship. For the purposes of this License, Derivative Works\nshall not include works that remain separable from, or merely link (or bind by\nname) to the interfaces of, the Work and Derivative Works thereof.\n\n\"Contribution\" shall mean any work of authorship, including the original version\nof the Work and any modifications or additions to that Work or Derivative Works\nthereof, that is intentionally submitted to Licensor for inclusion in the Work\nby the copyright owner or by an individual or Legal Entity authorized to submit\non behalf of the copyright owner. For the purposes of this definition,\n\"submitted\" means any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems, and\nissue tracking systems that are managed by, or on behalf of, the Licensor for\nthe purpose of discussing and improving the Work, but excluding communication\nthat is conspicuously marked or otherwise designated in writing by the copyright\nowner as \"Not a Contribution.\"\n\n\"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf\nof whom a Contribution has been received by Licensor and subsequently\nincorporated within the Work.\n\n2. Grant of Copyright License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable copyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the Work and such\nDerivative Works in Source or Object form.\n\n3. Grant of Patent License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable (except as stated in this section) patent license to make, have\nmade, use, offer to sell, sell, import, and otherwise transfer the Work, where\nsuch license applies only to those patent claims licensable by such Contributor\nthat are necessarily infringed by their Contribution(s) alone or by combination\nof their Contribution(s) with the Work to which such Contribution(s) was\nsubmitted. If You institute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work or a\nContribution incorporated within the Work constitutes direct or contributory\npatent infringement, then any patent licenses granted to You under this License\nfor that Work shall terminate as of the date such litigation is filed.\n\n4. Redistribution.\n\nYou may reproduce and distribute copies of the Work or Derivative Works thereof\nin any medium, with or without modifications, and in Source or Object form,\nprovided that You meet the following conditions:\n\nYou must give any other recipients of the Work or Derivative Works a copy of\nthis License; and\nYou must cause any modified files to carry prominent notices stating that You\nchanged the files; and\nYou must retain, in the Source form of any Derivative Works that You distribute,\nall copyright, patent, trademark, and attribution notices from the Source form\nof the Work, excluding those notices that do not pertain to any part of the\nDerivative Works; and\nIf the Work includes a \"NOTICE\" text file as part of its distribution, then any\nDerivative Works that You distribute must include a readable copy of the\nattribution notices contained within such NOTICE file, excluding those notices\nthat do not pertain to any part of the Derivative Works, in at least one of the\nfollowing places: within a NOTICE text file distributed as part of the\nDerivative Works; within the Source form or documentation, if provided along\nwith the Derivative Works; or, within a display generated by the Derivative\nWorks, if and wherever such third-party notices normally appear. The contents of\nthe NOTICE file are for informational purposes only and do not modify the\nLicense. You may add Your own attribution notices within Derivative Works that\nYou distribute, alongside or as an addendum to the NOTICE text from the Work,\nprovided that such additional attribution notices cannot be construed as\nmodifying the License.\nYou may add Your own copyright statement to Your modifications and may provide\nadditional or different license terms and conditions for use, reproduction, or\ndistribution of Your modifications, or for any such Derivative Works as a whole,\nprovided Your use, reproduction, and distribution of the Work otherwise complies\nwith the conditions stated in this License.\n\n5. Submission of Contributions.\n\nUnless You explicitly state otherwise, any Contribution intentionally submitted\nfor inclusion in the Work by You to the Licensor shall be under the terms and\nconditions of this License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify the terms of\nany separate license agreement you may have executed with Licensor regarding\nsuch Contributions.\n\n6. Trademarks.\n\nThis License does not grant permission to use the trade names, trademarks,\nservice marks, or product names of the Licensor, except as required for\nreasonable and customary use in describing the origin of the Work and\nreproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty.\n\nUnless required by applicable law or agreed to in writing, Licensor provides the\nWork (and each Contributor provides its Contributions) on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,\nincluding, without limitation, any warranties or conditions of TITLE,\nNON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are\nsolely responsible for determining the appropriateness of using or\nredistributing the Work and assume any risks associated with Your exercise of\npermissions under this License.\n\n8. Limitation of Liability.\n\nIn no event and under no legal theory, whether in tort (including negligence),\ncontract, or otherwise, unless required by applicable law (such as deliberate\nand grossly negligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special, incidental,\nor consequential damages of any character arising as a result of this License or\nout of the use or inability to use the Work (including but not limited to\ndamages for loss of goodwill, work stoppage, computer failure or malfunction, or\nany and all other commercial damages or losses), even if such Contributor has\nbeen advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability.\n\nWhile redistributing the Work or Derivative Works thereof, You may choose to\noffer, and charge a fee for, acceptance of support, warranty, indemnity, or\nother liability obligations and/or rights consistent with this License. However,\nin accepting such obligations, You may act only on Your own behalf and on Your\nsole responsibility, not on behalf of any other Contributor, and only if You\nagree to indemnify, defend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason of your\naccepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work\n\nTo apply the Apache License to your work, attach the following boilerplate\nnotice, with the fields enclosed by brackets \"[]\" replaced with your own\nidentifying information. (Don't include the brackets!) The text should be\nenclosed in the appropriate comment syntax for the file format. We also\nrecommend that a file or class name and description of purpose be included on\nthe same \"printed page\" as the copyright notice for easier identification within\nthird-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License." 986 986 }, 987 987 { 988 - "name": "github.com/urfave/cli", 989 - "path": "github.com/urfave/cli/LICENSE", 990 - "licenseText": "MIT License\n\nCopyright (c) 2023 Jeremy Saenz \u0026 Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" 988 + "name": "github.com/urfave/cli/v2", 989 + "path": "github.com/urfave/cli/v2/LICENSE", 990 + "licenseText": "MIT License\n\nCopyright (c) 2022 urfave/cli maintainers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" 991 991 }, 992 992 { 993 993 "name": "github.com/valyala/bytebufferpool", ··· 1018 1018 "name": "github.com/xanzy/ssh-agent", 1019 1019 "path": "github.com/xanzy/ssh-agent/LICENSE", 1020 1020 "licenseText": " Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"{}\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright {yyyy} {name of copyright owner}\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n" 1021 + }, 1022 + { 1023 + "name": "github.com/xrash/smetrics", 1024 + "path": "github.com/xrash/smetrics/LICENSE", 1025 + "licenseText": "Copyright (C) 2016 Felipe da Cunha Gonçalves\nAll Rights Reserved.\n\nMIT LICENSE\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" 1021 1026 }, 1022 1027 { 1023 1028 "name": "github.com/yohcop/openid-go",
+9 -8
cmd/actions.go
··· 9 9 "code.gitea.io/gitea/modules/private" 10 10 "code.gitea.io/gitea/modules/setting" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 15 var ( 16 16 // CmdActions represents the available actions sub-commands. 17 - CmdActions = cli.Command{ 17 + CmdActions = &cli.Command{ 18 18 Name: "actions", 19 19 Usage: "", 20 20 Description: "Commands for managing Gitea Actions", 21 - Subcommands: []cli.Command{ 21 + Subcommands: []*cli.Command{ 22 22 subcmdActionsGenRunnerToken, 23 23 }, 24 24 } 25 25 26 - subcmdActionsGenRunnerToken = cli.Command{ 26 + subcmdActionsGenRunnerToken = &cli.Command{ 27 27 Name: "generate-runner-token", 28 28 Usage: "Generate a new token for a runner to use to register with the server", 29 29 Action: runGenerateActionsRunnerToken, 30 30 Aliases: []string{"grt"}, 31 31 Flags: []cli.Flag{ 32 - cli.StringFlag{ 33 - Name: "scope, s", 34 - Value: "", 35 - Usage: "{owner}[/{repo}] - leave empty for a global runner", 32 + &cli.StringFlag{ 33 + Name: "scope", 34 + Aliases: []string{"s"}, 35 + Value: "", 36 + Usage: "{owner}[/{repo}] - leave empty for a global runner", 36 37 }, 37 38 }, 38 39 }
+67 -66
cmd/admin.go
··· 26 26 "code.gitea.io/gitea/services/auth/source/smtp" 27 27 repo_service "code.gitea.io/gitea/services/repository" 28 28 29 - "github.com/urfave/cli" 29 + "github.com/urfave/cli/v2" 30 30 ) 31 31 32 32 var ( 33 33 // CmdAdmin represents the available admin sub-command. 34 - CmdAdmin = cli.Command{ 34 + CmdAdmin = &cli.Command{ 35 35 Name: "admin", 36 36 Usage: "Command line interface to perform common administrative operations", 37 - Subcommands: []cli.Command{ 37 + Subcommands: []*cli.Command{ 38 38 subcmdUser, 39 39 subcmdRepoSyncReleases, 40 40 subcmdRegenerate, ··· 43 43 }, 44 44 } 45 45 46 - subcmdRepoSyncReleases = cli.Command{ 46 + subcmdRepoSyncReleases = &cli.Command{ 47 47 Name: "repo-sync-releases", 48 48 Usage: "Synchronize repository releases with tags", 49 49 Action: runRepoSyncReleases, 50 50 } 51 51 52 - subcmdRegenerate = cli.Command{ 52 + subcmdRegenerate = &cli.Command{ 53 53 Name: "regenerate", 54 54 Usage: "Regenerate specific files", 55 - Subcommands: []cli.Command{ 55 + Subcommands: []*cli.Command{ 56 56 microcmdRegenHooks, 57 57 microcmdRegenKeys, 58 58 }, 59 59 } 60 60 61 - microcmdRegenHooks = cli.Command{ 61 + microcmdRegenHooks = &cli.Command{ 62 62 Name: "hooks", 63 63 Usage: "Regenerate git-hooks", 64 64 Action: runRegenerateHooks, 65 65 } 66 66 67 - microcmdRegenKeys = cli.Command{ 67 + microcmdRegenKeys = &cli.Command{ 68 68 Name: "keys", 69 69 Usage: "Regenerate authorized_keys file", 70 70 Action: runRegenerateKeys, 71 71 } 72 72 73 - subcmdAuth = cli.Command{ 73 + subcmdAuth = &cli.Command{ 74 74 Name: "auth", 75 75 Usage: "Modify external auth providers", 76 - Subcommands: []cli.Command{ 76 + Subcommands: []*cli.Command{ 77 77 microcmdAuthAddOauth, 78 78 microcmdAuthUpdateOauth, 79 79 cmdAuthAddLdapBindDn, ··· 87 87 }, 88 88 } 89 89 90 - microcmdAuthList = cli.Command{ 90 + microcmdAuthList = &cli.Command{ 91 91 Name: "list", 92 92 Usage: "List auth sources", 93 93 Action: runListAuth, 94 94 Flags: []cli.Flag{ 95 - cli.IntFlag{ 95 + &cli.IntFlag{ 96 96 Name: "min-width", 97 97 Usage: "Minimal cell width including any padding for the formatted table", 98 98 Value: 0, 99 99 }, 100 - cli.IntFlag{ 100 + &cli.IntFlag{ 101 101 Name: "tab-width", 102 102 Usage: "width of tab characters in formatted table (equivalent number of spaces)", 103 103 Value: 8, 104 104 }, 105 - cli.IntFlag{ 105 + &cli.IntFlag{ 106 106 Name: "padding", 107 107 Usage: "padding added to a cell before computing its width", 108 108 Value: 1, 109 109 }, 110 - cli.StringFlag{ 110 + &cli.StringFlag{ 111 111 Name: "pad-char", 112 112 Usage: `ASCII char used for padding if padchar == '\\t', the Writer will assume that the width of a '\\t' in the formatted output is tabwidth, and cells are left-aligned independent of align_left (for correct-looking results, tabwidth must correspond to the tab width in the viewer displaying the result)`, 113 113 Value: "\t", 114 114 }, 115 - cli.BoolFlag{ 115 + &cli.BoolFlag{ 116 116 Name: "vertical-bars", 117 117 Usage: "Set to true to print vertical bars between columns", 118 118 }, 119 119 }, 120 120 } 121 121 122 - idFlag = cli.Int64Flag{ 122 + idFlag = &cli.Int64Flag{ 123 123 Name: "id", 124 124 Usage: "ID of authentication source", 125 125 } 126 126 127 - microcmdAuthDelete = cli.Command{ 127 + microcmdAuthDelete = &cli.Command{ 128 128 Name: "delete", 129 129 Usage: "Delete specific auth source", 130 130 Flags: []cli.Flag{idFlag}, ··· 132 132 } 133 133 134 134 oauthCLIFlags = []cli.Flag{ 135 - cli.StringFlag{ 135 + &cli.StringFlag{ 136 136 Name: "name", 137 137 Value: "", 138 138 Usage: "Application Name", 139 139 }, 140 - cli.StringFlag{ 140 + &cli.StringFlag{ 141 141 Name: "provider", 142 142 Value: "", 143 143 Usage: "OAuth2 Provider", 144 144 }, 145 - cli.StringFlag{ 145 + &cli.StringFlag{ 146 146 Name: "key", 147 147 Value: "", 148 148 Usage: "Client ID (Key)", 149 149 }, 150 - cli.StringFlag{ 150 + &cli.StringFlag{ 151 151 Name: "secret", 152 152 Value: "", 153 153 Usage: "Client Secret", 154 154 }, 155 - cli.StringFlag{ 155 + &cli.StringFlag{ 156 156 Name: "auto-discover-url", 157 157 Value: "", 158 158 Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", 159 159 }, 160 - cli.StringFlag{ 160 + &cli.StringFlag{ 161 161 Name: "use-custom-urls", 162 162 Value: "false", 163 163 Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", 164 164 }, 165 - cli.StringFlag{ 165 + &cli.StringFlag{ 166 166 Name: "custom-tenant-id", 167 167 Value: "", 168 168 Usage: "Use custom Tenant ID for OAuth endpoints", 169 169 }, 170 - cli.StringFlag{ 170 + &cli.StringFlag{ 171 171 Name: "custom-auth-url", 172 172 Value: "", 173 173 Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", 174 174 }, 175 - cli.StringFlag{ 175 + &cli.StringFlag{ 176 176 Name: "custom-token-url", 177 177 Value: "", 178 178 Usage: "Use a custom Token URL (option for GitLab/GitHub)", 179 179 }, 180 - cli.StringFlag{ 180 + &cli.StringFlag{ 181 181 Name: "custom-profile-url", 182 182 Value: "", 183 183 Usage: "Use a custom Profile URL (option for GitLab/GitHub)", 184 184 }, 185 - cli.StringFlag{ 185 + &cli.StringFlag{ 186 186 Name: "custom-email-url", 187 187 Value: "", 188 188 Usage: "Use a custom Email URL (option for GitHub)", 189 189 }, 190 - cli.StringFlag{ 190 + &cli.StringFlag{ 191 191 Name: "icon-url", 192 192 Value: "", 193 193 Usage: "Custom icon URL for OAuth2 login source", 194 194 }, 195 - cli.BoolFlag{ 195 + &cli.BoolFlag{ 196 196 Name: "skip-local-2fa", 197 197 Usage: "Set to true to skip local 2fa for users authenticated by this source", 198 198 }, 199 - cli.StringSliceFlag{ 199 + &cli.StringSliceFlag{ 200 200 Name: "scopes", 201 201 Value: nil, 202 202 Usage: "Scopes to request when to authenticate against this OAuth2 source", 203 203 }, 204 - cli.StringFlag{ 204 + &cli.StringFlag{ 205 205 Name: "required-claim-name", 206 206 Value: "", 207 207 Usage: "Claim name that has to be set to allow users to login with this source", 208 208 }, 209 - cli.StringFlag{ 209 + &cli.StringFlag{ 210 210 Name: "required-claim-value", 211 211 Value: "", 212 212 Usage: "Claim value that has to be set to allow users to login with this source", 213 213 }, 214 - cli.StringFlag{ 214 + &cli.StringFlag{ 215 215 Name: "group-claim-name", 216 216 Value: "", 217 217 Usage: "Claim name providing group names for this source", 218 218 }, 219 - cli.StringFlag{ 219 + &cli.StringFlag{ 220 220 Name: "admin-group", 221 221 Value: "", 222 222 Usage: "Group Claim value for administrator users", 223 223 }, 224 - cli.StringFlag{ 224 + &cli.StringFlag{ 225 225 Name: "restricted-group", 226 226 Value: "", 227 227 Usage: "Group Claim value for restricted users", 228 228 }, 229 - cli.StringFlag{ 229 + &cli.StringFlag{ 230 230 Name: "group-team-map", 231 231 Value: "", 232 232 Usage: "JSON mapping between groups and org teams", 233 233 }, 234 - cli.BoolFlag{ 234 + &cli.BoolFlag{ 235 235 Name: "group-team-map-removal", 236 236 Usage: "Activate automatic team membership removal depending on groups", 237 237 }, 238 238 } 239 239 240 - microcmdAuthUpdateOauth = cli.Command{ 240 + microcmdAuthUpdateOauth = &cli.Command{ 241 241 Name: "update-oauth", 242 242 Usage: "Update existing Oauth authentication source", 243 243 Action: runUpdateOauth, 244 244 Flags: append(oauthCLIFlags[:1], append([]cli.Flag{idFlag}, oauthCLIFlags[1:]...)...), 245 245 } 246 246 247 - microcmdAuthAddOauth = cli.Command{ 247 + microcmdAuthAddOauth = &cli.Command{ 248 248 Name: "add-oauth", 249 249 Usage: "Add new Oauth authentication source", 250 250 Action: runAddOauth, 251 251 Flags: oauthCLIFlags, 252 252 } 253 253 254 - subcmdSendMail = cli.Command{ 254 + subcmdSendMail = &cli.Command{ 255 255 Name: "sendmail", 256 256 Usage: "Send a message to all users", 257 257 Action: runSendMail, 258 258 Flags: []cli.Flag{ 259 - cli.StringFlag{ 259 + &cli.StringFlag{ 260 260 Name: "title", 261 261 Usage: `a title of a message`, 262 262 Value: "", 263 263 }, 264 - cli.StringFlag{ 264 + &cli.StringFlag{ 265 265 Name: "content", 266 266 Usage: "a content of a message", 267 267 Value: "", 268 268 }, 269 - cli.BoolFlag{ 270 - Name: "force,f", 271 - Usage: "A flag to bypass a confirmation step", 269 + &cli.BoolFlag{ 270 + Name: "force", 271 + Aliases: []string{"f"}, 272 + Usage: "A flag to bypass a confirmation step", 272 273 }, 273 274 }, 274 275 } 275 276 276 277 smtpCLIFlags = []cli.Flag{ 277 - cli.StringFlag{ 278 + &cli.StringFlag{ 278 279 Name: "name", 279 280 Value: "", 280 281 Usage: "Application Name", 281 282 }, 282 - cli.StringFlag{ 283 + &cli.StringFlag{ 283 284 Name: "auth-type", 284 285 Value: "PLAIN", 285 286 Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN", 286 287 }, 287 - cli.StringFlag{ 288 + &cli.StringFlag{ 288 289 Name: "host", 289 290 Value: "", 290 291 Usage: "SMTP Host", 291 292 }, 292 - cli.IntFlag{ 293 + &cli.IntFlag{ 293 294 Name: "port", 294 295 Usage: "SMTP Port", 295 296 }, 296 - cli.BoolTFlag{ 297 + &cli.BoolFlag{ 297 298 Name: "force-smtps", 298 299 Usage: "SMTPS is always used on port 465. Set this to force SMTPS on other ports.", 299 300 }, 300 - cli.BoolTFlag{ 301 + &cli.BoolFlag{ 301 302 Name: "skip-verify", 302 303 Usage: "Skip TLS verify.", 303 304 }, 304 - cli.StringFlag{ 305 + &cli.StringFlag{ 305 306 Name: "helo-hostname", 306 307 Value: "", 307 308 Usage: "Hostname sent with HELO. Leave blank to send current hostname", 308 309 }, 309 - cli.BoolTFlag{ 310 + &cli.BoolFlag{ 310 311 Name: "disable-helo", 311 312 Usage: "Disable SMTP helo.", 312 313 }, 313 - cli.StringFlag{ 314 + &cli.StringFlag{ 314 315 Name: "allowed-domains", 315 316 Value: "", 316 317 Usage: "Leave empty to allow all domains. Separate multiple domains with a comma (',')", 317 318 }, 318 - cli.BoolTFlag{ 319 + &cli.BoolFlag{ 319 320 Name: "skip-local-2fa", 320 321 Usage: "Skip 2FA to log on.", 321 322 }, 322 - cli.BoolTFlag{ 323 + &cli.BoolFlag{ 323 324 Name: "active", 324 325 Usage: "This Authentication Source is Activated.", 325 326 }, 326 327 } 327 328 328 - microcmdAuthAddSMTP = cli.Command{ 329 + microcmdAuthAddSMTP = &cli.Command{ 329 330 Name: "add-smtp", 330 331 Usage: "Add new SMTP authentication source", 331 332 Action: runAddSMTP, 332 333 Flags: smtpCLIFlags, 333 334 } 334 335 335 - microcmdAuthUpdateSMTP = cli.Command{ 336 + microcmdAuthUpdateSMTP = &cli.Command{ 336 337 Name: "update-smtp", 337 338 Usage: "Update existing SMTP authentication source", 338 339 Action: runUpdateSMTP, ··· 611 612 conf.AllowedDomains = c.String("allowed-domains") 612 613 } 613 614 if c.IsSet("force-smtps") { 614 - conf.ForceSMTPS = c.BoolT("force-smtps") 615 + conf.ForceSMTPS = c.Bool("force-smtps") 615 616 } 616 617 if c.IsSet("skip-verify") { 617 - conf.SkipVerify = c.BoolT("skip-verify") 618 + conf.SkipVerify = c.Bool("skip-verify") 618 619 } 619 620 if c.IsSet("helo-hostname") { 620 621 conf.HeloHostname = c.String("helo-hostname") 621 622 } 622 623 if c.IsSet("disable-helo") { 623 - conf.DisableHelo = c.BoolT("disable-helo") 624 + conf.DisableHelo = c.Bool("disable-helo") 624 625 } 625 626 if c.IsSet("skip-local-2fa") { 626 - conf.SkipLocalTwoFA = c.BoolT("skip-local-2fa") 627 + conf.SkipLocalTwoFA = c.Bool("skip-local-2fa") 627 628 } 628 629 return nil 629 630 } ··· 647 648 } 648 649 active := true 649 650 if c.IsSet("active") { 650 - active = c.BoolT("active") 651 + active = c.Bool("active") 651 652 } 652 653 653 654 var smtpConfig smtp.Source ··· 696 697 } 697 698 698 699 if c.IsSet("active") { 699 - source.IsActive = c.BoolT("active") 700 + source.IsActive = c.Bool("active") 700 701 } 701 702 702 703 source.Cfg = smtpConfig
+31 -31
cmd/admin_auth_ldap.go
··· 11 11 "code.gitea.io/gitea/models/auth" 12 12 "code.gitea.io/gitea/services/auth/source/ldap" 13 13 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 17 type ( ··· 25 25 26 26 var ( 27 27 commonLdapCLIFlags = []cli.Flag{ 28 - cli.StringFlag{ 28 + &cli.StringFlag{ 29 29 Name: "name", 30 30 Usage: "Authentication name.", 31 31 }, 32 - cli.BoolFlag{ 32 + &cli.BoolFlag{ 33 33 Name: "not-active", 34 34 Usage: "Deactivate the authentication source.", 35 35 }, 36 - cli.BoolFlag{ 36 + &cli.BoolFlag{ 37 37 Name: "active", 38 38 Usage: "Activate the authentication source.", 39 39 }, 40 - cli.StringFlag{ 40 + &cli.StringFlag{ 41 41 Name: "security-protocol", 42 42 Usage: "Security protocol name.", 43 43 }, 44 - cli.BoolFlag{ 44 + &cli.BoolFlag{ 45 45 Name: "skip-tls-verify", 46 46 Usage: "Disable TLS verification.", 47 47 }, 48 - cli.StringFlag{ 48 + &cli.StringFlag{ 49 49 Name: "host", 50 50 Usage: "The address where the LDAP server can be reached.", 51 51 }, 52 - cli.IntFlag{ 52 + &cli.IntFlag{ 53 53 Name: "port", 54 54 Usage: "The port to use when connecting to the LDAP server.", 55 55 }, 56 - cli.StringFlag{ 56 + &cli.StringFlag{ 57 57 Name: "user-search-base", 58 58 Usage: "The LDAP base at which user accounts will be searched for.", 59 59 }, 60 - cli.StringFlag{ 60 + &cli.StringFlag{ 61 61 Name: "user-filter", 62 62 Usage: "An LDAP filter declaring how to find the user record that is attempting to authenticate.", 63 63 }, 64 - cli.StringFlag{ 64 + &cli.StringFlag{ 65 65 Name: "admin-filter", 66 66 Usage: "An LDAP filter specifying if a user should be given administrator privileges.", 67 67 }, 68 - cli.StringFlag{ 68 + &cli.StringFlag{ 69 69 Name: "restricted-filter", 70 70 Usage: "An LDAP filter specifying if a user should be given restricted status.", 71 71 }, 72 - cli.BoolFlag{ 72 + &cli.BoolFlag{ 73 73 Name: "allow-deactivate-all", 74 74 Usage: "Allow empty search results to deactivate all users.", 75 75 }, 76 - cli.StringFlag{ 76 + &cli.StringFlag{ 77 77 Name: "username-attribute", 78 78 Usage: "The attribute of the user’s LDAP record containing the user name.", 79 79 }, 80 - cli.StringFlag{ 80 + &cli.StringFlag{ 81 81 Name: "firstname-attribute", 82 82 Usage: "The attribute of the user’s LDAP record containing the user’s first name.", 83 83 }, 84 - cli.StringFlag{ 84 + &cli.StringFlag{ 85 85 Name: "surname-attribute", 86 86 Usage: "The attribute of the user’s LDAP record containing the user’s surname.", 87 87 }, 88 - cli.StringFlag{ 88 + &cli.StringFlag{ 89 89 Name: "email-attribute", 90 90 Usage: "The attribute of the user’s LDAP record containing the user’s email address.", 91 91 }, 92 - cli.StringFlag{ 92 + &cli.StringFlag{ 93 93 Name: "public-ssh-key-attribute", 94 94 Usage: "The attribute of the user’s LDAP record containing the user’s public ssh key.", 95 95 }, 96 - cli.BoolFlag{ 96 + &cli.BoolFlag{ 97 97 Name: "skip-local-2fa", 98 98 Usage: "Set to true to skip local 2fa for users authenticated by this source", 99 99 }, 100 - cli.StringFlag{ 100 + &cli.StringFlag{ 101 101 Name: "avatar-attribute", 102 102 Usage: "The attribute of the user’s LDAP record containing the user’s avatar.", 103 103 }, 104 104 } 105 105 106 106 ldapBindDnCLIFlags = append(commonLdapCLIFlags, 107 - cli.StringFlag{ 107 + &cli.StringFlag{ 108 108 Name: "bind-dn", 109 109 Usage: "The DN to bind to the LDAP server with when searching for the user.", 110 110 }, 111 - cli.StringFlag{ 111 + &cli.StringFlag{ 112 112 Name: "bind-password", 113 113 Usage: "The password for the Bind DN, if any.", 114 114 }, 115 - cli.BoolFlag{ 115 + &cli.BoolFlag{ 116 116 Name: "attributes-in-bind", 117 117 Usage: "Fetch attributes in bind DN context.", 118 118 }, 119 - cli.BoolFlag{ 119 + &cli.BoolFlag{ 120 120 Name: "synchronize-users", 121 121 Usage: "Enable user synchronization.", 122 122 }, 123 - cli.BoolFlag{ 123 + &cli.BoolFlag{ 124 124 Name: "disable-synchronize-users", 125 125 Usage: "Disable user synchronization.", 126 126 }, 127 - cli.UintFlag{ 127 + &cli.UintFlag{ 128 128 Name: "page-size", 129 129 Usage: "Search page size.", 130 130 }) 131 131 132 132 ldapSimpleAuthCLIFlags = append(commonLdapCLIFlags, 133 - cli.StringFlag{ 133 + &cli.StringFlag{ 134 134 Name: "user-dn", 135 135 Usage: "The user’s DN.", 136 136 }) 137 137 138 - cmdAuthAddLdapBindDn = cli.Command{ 138 + cmdAuthAddLdapBindDn = &cli.Command{ 139 139 Name: "add-ldap", 140 140 Usage: "Add new LDAP (via Bind DN) authentication source", 141 141 Action: func(c *cli.Context) error { ··· 144 144 Flags: ldapBindDnCLIFlags, 145 145 } 146 146 147 - cmdAuthUpdateLdapBindDn = cli.Command{ 147 + cmdAuthUpdateLdapBindDn = &cli.Command{ 148 148 Name: "update-ldap", 149 149 Usage: "Update existing LDAP (via Bind DN) authentication source", 150 150 Action: func(c *cli.Context) error { ··· 153 153 Flags: append([]cli.Flag{idFlag}, ldapBindDnCLIFlags...), 154 154 } 155 155 156 - cmdAuthAddLdapSimpleAuth = cli.Command{ 156 + cmdAuthAddLdapSimpleAuth = &cli.Command{ 157 157 Name: "add-ldap-simple", 158 158 Usage: "Add new LDAP (simple auth) authentication source", 159 159 Action: func(c *cli.Context) error { ··· 162 162 Flags: ldapSimpleAuthCLIFlags, 163 163 } 164 164 165 - cmdAuthUpdateLdapSimpleAuth = cli.Command{ 165 + cmdAuthUpdateLdapSimpleAuth = &cli.Command{ 166 166 Name: "update-ldap-simple", 167 167 Usage: "Update existing LDAP (simple auth) authentication source", 168 168 Action: func(c *cli.Context) error {
+1 -1
cmd/admin_auth_ldap_test.go
··· 11 11 "code.gitea.io/gitea/services/auth/source/ldap" 12 12 13 13 "github.com/stretchr/testify/assert" 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 17 func TestAddLdapBindDn(t *testing.T) {
+3 -3
cmd/admin_user.go
··· 4 4 package cmd 5 5 6 6 import ( 7 - "github.com/urfave/cli" 7 + "github.com/urfave/cli/v2" 8 8 ) 9 9 10 - var subcmdUser = cli.Command{ 10 + var subcmdUser = &cli.Command{ 11 11 Name: "user", 12 12 Usage: "Modify users", 13 - Subcommands: []cli.Command{ 13 + Subcommands: []*cli.Command{ 14 14 microcmdUserCreate, 15 15 microcmdUserList, 16 16 microcmdUserChangePassword,
+12 -10
cmd/admin_user_change_password.go
··· 12 12 pwd "code.gitea.io/gitea/modules/auth/password" 13 13 "code.gitea.io/gitea/modules/setting" 14 14 15 - "github.com/urfave/cli" 15 + "github.com/urfave/cli/v2" 16 16 ) 17 17 18 - var microcmdUserChangePassword = cli.Command{ 18 + var microcmdUserChangePassword = &cli.Command{ 19 19 Name: "change-password", 20 20 Usage: "Change a user's password", 21 21 Action: runChangePassword, 22 22 Flags: []cli.Flag{ 23 - cli.StringFlag{ 24 - Name: "username,u", 25 - Value: "", 26 - Usage: "The user to change password for", 23 + &cli.StringFlag{ 24 + Name: "username", 25 + Aliases: []string{"u"}, 26 + Value: "", 27 + Usage: "The user to change password for", 27 28 }, 28 - cli.StringFlag{ 29 - Name: "password,p", 30 - Value: "", 31 - Usage: "New password to set for user", 29 + &cli.StringFlag{ 30 + Name: "password", 31 + Aliases: []string{"p"}, 32 + Value: "", 33 + Usage: "New password to set for user", 32 34 }, 33 35 }, 34 36 }
+12 -12
cmd/admin_user_create.go
··· 14 14 "code.gitea.io/gitea/modules/setting" 15 15 "code.gitea.io/gitea/modules/util" 16 16 17 - "github.com/urfave/cli" 17 + "github.com/urfave/cli/v2" 18 18 ) 19 19 20 - var microcmdUserCreate = cli.Command{ 20 + var microcmdUserCreate = &cli.Command{ 21 21 Name: "create", 22 22 Usage: "Create a new user in database", 23 23 Action: runCreateUser, 24 24 Flags: []cli.Flag{ 25 - cli.StringFlag{ 25 + &cli.StringFlag{ 26 26 Name: "name", 27 27 Usage: "Username. DEPRECATED: use username instead", 28 28 }, 29 - cli.StringFlag{ 29 + &cli.StringFlag{ 30 30 Name: "username", 31 31 Usage: "Username", 32 32 }, 33 - cli.StringFlag{ 33 + &cli.StringFlag{ 34 34 Name: "password", 35 35 Usage: "User password", 36 36 }, 37 - cli.StringFlag{ 37 + &cli.StringFlag{ 38 38 Name: "email", 39 39 Usage: "User email address", 40 40 }, 41 - cli.BoolFlag{ 41 + &cli.BoolFlag{ 42 42 Name: "admin", 43 43 Usage: "User is an admin", 44 44 }, 45 - cli.BoolFlag{ 45 + &cli.BoolFlag{ 46 46 Name: "random-password", 47 47 Usage: "Generate a random password for the user", 48 48 }, 49 - cli.BoolFlag{ 49 + &cli.BoolFlag{ 50 50 Name: "must-change-password", 51 51 Usage: "Set this option to false to prevent forcing the user to change their password after initial login, (Default: true)", 52 52 }, 53 - cli.IntFlag{ 53 + &cli.IntFlag{ 54 54 Name: "random-password-length", 55 55 Usage: "Length of the random password to be generated", 56 56 Value: 12, 57 57 }, 58 - cli.BoolFlag{ 58 + &cli.BoolFlag{ 59 59 Name: "access-token", 60 60 Usage: "Generate access token for the user", 61 61 }, 62 - cli.BoolFlag{ 62 + &cli.BoolFlag{ 63 63 Name: "restricted", 64 64 Usage: "Make a restricted user account", 65 65 },
+12 -10
cmd/admin_user_delete.go
··· 11 11 "code.gitea.io/gitea/modules/storage" 12 12 user_service "code.gitea.io/gitea/services/user" 13 13 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 - var microcmdUserDelete = cli.Command{ 17 + var microcmdUserDelete = &cli.Command{ 18 18 Name: "delete", 19 19 Usage: "Delete specific user by id, name or email", 20 20 Flags: []cli.Flag{ 21 - cli.Int64Flag{ 21 + &cli.Int64Flag{ 22 22 Name: "id", 23 23 Usage: "ID of user of the user to delete", 24 24 }, 25 - cli.StringFlag{ 26 - Name: "username,u", 27 - Usage: "Username of the user to delete", 25 + &cli.StringFlag{ 26 + Name: "username", 27 + Aliases: []string{"u"}, 28 + Usage: "Username of the user to delete", 28 29 }, 29 - cli.StringFlag{ 30 - Name: "email,e", 31 - Usage: "Email of the user to delete", 30 + &cli.StringFlag{ 31 + Name: "email", 32 + Aliases: []string{"e"}, 33 + Usage: "Email of the user to delete", 32 34 }, 33 - cli.BoolFlag{ 35 + &cli.BoolFlag{ 34 36 Name: "purge", 35 37 Usage: "Purge user, all their repositories, organizations and comments", 36 38 },
+13 -11
cmd/admin_user_generate_access_token.go
··· 9 9 auth_model "code.gitea.io/gitea/models/auth" 10 10 user_model "code.gitea.io/gitea/models/user" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 - var microcmdUserGenerateAccessToken = cli.Command{ 15 + var microcmdUserGenerateAccessToken = &cli.Command{ 16 16 Name: "generate-access-token", 17 17 Usage: "Generate an access token for a specific user", 18 18 Flags: []cli.Flag{ 19 - cli.StringFlag{ 20 - Name: "username,u", 21 - Usage: "Username", 19 + &cli.StringFlag{ 20 + Name: "username", 21 + Aliases: []string{"u"}, 22 + Usage: "Username", 22 23 }, 23 - cli.StringFlag{ 24 - Name: "token-name,t", 25 - Usage: "Token name", 26 - Value: "gitea-admin", 24 + &cli.StringFlag{ 25 + Name: "token-name", 26 + Aliases: []string{"t"}, 27 + Usage: "Token name", 28 + Value: "gitea-admin", 27 29 }, 28 - cli.BoolFlag{ 30 + &cli.BoolFlag{ 29 31 Name: "raw", 30 32 Usage: "Display only the token value", 31 33 }, 32 - cli.StringFlag{ 34 + &cli.StringFlag{ 33 35 Name: "scopes", 34 36 Value: "", 35 37 Usage: "Comma separated list of scopes to apply to access token",
+3 -3
cmd/admin_user_list.go
··· 10 10 11 11 user_model "code.gitea.io/gitea/models/user" 12 12 13 - "github.com/urfave/cli" 13 + "github.com/urfave/cli/v2" 14 14 ) 15 15 16 - var microcmdUserList = cli.Command{ 16 + var microcmdUserList = &cli.Command{ 17 17 Name: "list", 18 18 Usage: "List users", 19 19 Action: runListUsers, 20 20 Flags: []cli.Flag{ 21 - cli.BoolFlag{ 21 + &cli.BoolFlag{ 22 22 Name: "admin", 23 23 Usage: "List only admin users", 24 24 },
+12 -10
cmd/admin_user_must_change_password.go
··· 9 9 10 10 user_model "code.gitea.io/gitea/models/user" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 - var microcmdUserMustChangePassword = cli.Command{ 15 + var microcmdUserMustChangePassword = &cli.Command{ 16 16 Name: "must-change-password", 17 17 Usage: "Set the must change password flag for the provided users or all users", 18 18 Action: runMustChangePassword, 19 19 Flags: []cli.Flag{ 20 - cli.BoolFlag{ 21 - Name: "all,A", 22 - Usage: "All users must change password, except those explicitly excluded with --exclude", 20 + &cli.BoolFlag{ 21 + Name: "all", 22 + Aliases: []string{"A"}, 23 + Usage: "All users must change password, except those explicitly excluded with --exclude", 23 24 }, 24 - cli.StringSliceFlag{ 25 - Name: "exclude,e", 26 - Usage: "Do not change the must-change-password flag for these users", 25 + &cli.StringSliceFlag{ 26 + Name: "exclude", 27 + Aliases: []string{"e"}, 28 + Usage: "Do not change the must-change-password flag for these users", 27 29 }, 28 - cli.BoolFlag{ 30 + &cli.BoolFlag{ 29 31 Name: "unset", 30 32 Usage: "Instead of setting the must-change-password flag, unset it", 31 33 }, ··· 48 50 return err 49 51 } 50 52 51 - n, err := user_model.SetMustChangePassword(ctx, all, mustChangePassword, c.Args(), exclude) 53 + n, err := user_model.SetMustChangePassword(ctx, all, mustChangePassword, c.Args().Slice(), exclude) 52 54 if err != nil { 53 55 return err 54 56 }
+8 -8
cmd/cert.go
··· 20 20 "strings" 21 21 "time" 22 22 23 - "github.com/urfave/cli" 23 + "github.com/urfave/cli/v2" 24 24 ) 25 25 26 26 // CmdCert represents the available cert sub-command. 27 - var CmdCert = cli.Command{ 27 + var CmdCert = &cli.Command{ 28 28 Name: "cert", 29 29 Usage: "Generate self-signed certificate", 30 30 Description: `Generate a self-signed X.509 certificate for a TLS server. 31 31 Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`, 32 32 Action: runCert, 33 33 Flags: []cli.Flag{ 34 - cli.StringFlag{ 34 + &cli.StringFlag{ 35 35 Name: "host", 36 36 Value: "", 37 37 Usage: "Comma-separated hostnames and IPs to generate a certificate for", 38 38 }, 39 - cli.StringFlag{ 39 + &cli.StringFlag{ 40 40 Name: "ecdsa-curve", 41 41 Value: "", 42 42 Usage: "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", 43 43 }, 44 - cli.IntFlag{ 44 + &cli.IntFlag{ 45 45 Name: "rsa-bits", 46 46 Value: 2048, 47 47 Usage: "Size of RSA key to generate. Ignored if --ecdsa-curve is set", 48 48 }, 49 - cli.StringFlag{ 49 + &cli.StringFlag{ 50 50 Name: "start-date", 51 51 Value: "", 52 52 Usage: "Creation date formatted as Jan 1 15:04:05 2011", 53 53 }, 54 - cli.DurationFlag{ 54 + &cli.DurationFlag{ 55 55 Name: "duration", 56 56 Value: 365 * 24 * time.Hour, 57 57 Usage: "Duration that certificate is valid for", 58 58 }, 59 - cli.BoolFlag{ 59 + &cli.BoolFlag{ 60 60 Name: "ca", 61 61 Usage: "whether this cert should be its own Certificate Authority", 62 62 },
+12 -3
cmd/cmd.go
··· 20 20 "code.gitea.io/gitea/modules/setting" 21 21 "code.gitea.io/gitea/modules/util" 22 22 23 - "github.com/urfave/cli" 23 + "github.com/urfave/cli/v2" 24 24 ) 25 25 26 26 // argsSet checks that all the required arguments are set. args is a list of ··· 109 109 log.GetManager().GetLogger(log.DEFAULT).ReplaceAllWriters(writer) 110 110 } 111 111 112 + func globalBool(c *cli.Context, name string) bool { 113 + for _, ctx := range c.Lineage() { 114 + if ctx.Bool(name) { 115 + return true 116 + } 117 + } 118 + return false 119 + } 120 + 112 121 // PrepareConsoleLoggerLevel by default, use INFO level for console logger, but some sub-commands (for git/ssh protocol) shouldn't output any log to stdout. 113 122 // Any log appears in git stdout pipe will break the git protocol, eg: client can't push and hangs forever. 114 123 func PrepareConsoleLoggerLevel(defaultLevel log.Level) func(*cli.Context) error { 115 124 return func(c *cli.Context) error { 116 125 level := defaultLevel 117 - if c.Bool("quiet") || c.GlobalBoolT("quiet") { 126 + if globalBool(c, "quiet") { 118 127 level = log.FATAL 119 128 } 120 - if c.Bool("debug") || c.GlobalBool("debug") || c.Bool("verbose") || c.GlobalBool("verbose") { 129 + if globalBool(c, "debug") || globalBool(c, "verbose") { 121 130 level = log.TRACE 122 131 } 123 132 log.SetConsoleLogger(log.DEFAULT, "console-default", level)
+2 -2
cmd/convert.go
··· 10 10 "code.gitea.io/gitea/modules/log" 11 11 "code.gitea.io/gitea/modules/setting" 12 12 13 - "github.com/urfave/cli" 13 + "github.com/urfave/cli/v2" 14 14 ) 15 15 16 16 // CmdConvert represents the available convert sub-command. 17 - var CmdConvert = cli.Command{ 17 + var CmdConvert = &cli.Command{ 18 18 Name: "convert", 19 19 Usage: "Convert the database", 20 20 Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
+5 -4
cmd/docs.go
··· 8 8 "os" 9 9 "strings" 10 10 11 - "github.com/urfave/cli" 11 + "github.com/urfave/cli/v2" 12 12 ) 13 13 14 14 // CmdDocs represents the available docs sub-command. 15 - var CmdDocs = cli.Command{ 15 + var CmdDocs = &cli.Command{ 16 16 Name: "docs", 17 17 Usage: "Output CLI documentation", 18 18 Description: "A command to output Gitea's CLI documentation, optionally to a file.", ··· 23 23 Usage: "Output man pages instead", 24 24 }, 25 25 &cli.StringFlag{ 26 - Name: "output, o", 27 - Usage: "Path to output to instead of stdout (will overwrite if exists)", 26 + Name: "output", 27 + Aliases: []string{"o"}, 28 + Usage: "Path to output to instead of stdout (will overwrite if exists)", 28 29 }, 29 30 }, 30 31 }
+15 -14
cmd/doctor.go
··· 18 18 "code.gitea.io/gitea/modules/log" 19 19 "code.gitea.io/gitea/modules/setting" 20 20 21 - "github.com/urfave/cli" 21 + "github.com/urfave/cli/v2" 22 22 "xorm.io/xorm" 23 23 ) 24 24 25 25 // CmdDoctor represents the available doctor sub-command. 26 - var CmdDoctor = cli.Command{ 26 + var CmdDoctor = &cli.Command{ 27 27 Name: "doctor", 28 28 Usage: "Diagnose and optionally fix problems", 29 29 Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.", 30 30 Action: runDoctor, 31 31 Flags: []cli.Flag{ 32 - cli.BoolFlag{ 32 + &cli.BoolFlag{ 33 33 Name: "list", 34 34 Usage: "List the available checks", 35 35 }, 36 - cli.BoolFlag{ 36 + &cli.BoolFlag{ 37 37 Name: "default", 38 38 Usage: "Run the default checks (if neither --run or --all is set, this is the default behaviour)", 39 39 }, 40 - cli.StringSliceFlag{ 40 + &cli.StringSliceFlag{ 41 41 Name: "run", 42 42 Usage: "Run the provided checks - (if --default is set, the default checks will also run)", 43 43 }, 44 - cli.BoolFlag{ 44 + &cli.BoolFlag{ 45 45 Name: "all", 46 46 Usage: "Run all the available checks", 47 47 }, 48 - cli.BoolFlag{ 48 + &cli.BoolFlag{ 49 49 Name: "fix", 50 50 Usage: "Automatically fix what we can", 51 51 }, 52 - cli.StringFlag{ 52 + &cli.StringFlag{ 53 53 Name: "log-file", 54 54 Usage: `Name of the log file (default: "doctor.log"). Set to "-" to output to stdout, set to "" to disable`, 55 55 }, 56 - cli.BoolFlag{ 57 - Name: "color, H", 58 - Usage: "Use color for outputted information", 56 + &cli.BoolFlag{ 57 + Name: "color", 58 + Aliases: []string{"H"}, 59 + Usage: "Use color for outputted information", 59 60 }, 60 61 }, 61 - Subcommands: []cli.Command{ 62 + Subcommands: []*cli.Command{ 62 63 cmdRecreateTable, 63 64 }, 64 65 } 65 66 66 - var cmdRecreateTable = cli.Command{ 67 + var cmdRecreateTable = &cli.Command{ 67 68 Name: "recreate-table", 68 69 Usage: "Recreate tables from XORM definitions and copy the data.", 69 70 ArgsUsage: "[TABLE]... : (TABLEs to recreate - leave blank for all)", 70 71 Flags: []cli.Flag{ 71 - cli.BoolFlag{ 72 + &cli.BoolFlag{ 72 73 Name: "debug", 73 74 Usage: "Print SQL commands sent", 74 75 },
+38 -31
cmd/dump.go
··· 22 22 23 23 "gitea.com/go-chi/session" 24 24 "github.com/mholt/archiver/v3" 25 - "github.com/urfave/cli" 25 + "github.com/urfave/cli/v2" 26 26 ) 27 27 28 28 func addReader(w archiver.Writer, r io.ReadCloser, info os.FileInfo, customName string, verbose bool) error { ··· 96 96 } 97 97 98 98 // CmdDump represents the available dump sub-command. 99 - var CmdDump = cli.Command{ 99 + var CmdDump = &cli.Command{ 100 100 Name: "dump", 101 101 Usage: "Dump Gitea files and database", 102 102 Description: `Dump compresses all related files and database into zip file. 103 103 It can be used for backup and capture Gitea server image to send to maintainer`, 104 104 Action: runDump, 105 105 Flags: []cli.Flag{ 106 - cli.StringFlag{ 107 - Name: "file, f", 108 - Value: fmt.Sprintf("gitea-dump-%d.zip", time.Now().Unix()), 109 - Usage: "Name of the dump file which will be created. Supply '-' for stdout. See type for available types.", 106 + &cli.StringFlag{ 107 + Name: "file", 108 + Aliases: []string{"f"}, 109 + Value: fmt.Sprintf("gitea-dump-%d.zip", time.Now().Unix()), 110 + Usage: "Name of the dump file which will be created. Supply '-' for stdout. See type for available types.", 110 111 }, 111 - cli.BoolFlag{ 112 - Name: "verbose, V", 113 - Usage: "Show process details", 112 + &cli.BoolFlag{ 113 + Name: "verbose", 114 + Aliases: []string{"V"}, 115 + Usage: "Show process details", 114 116 }, 115 - cli.BoolFlag{ 116 - Name: "quiet, q", 117 - Usage: "Only display warnings and errors", 117 + &cli.BoolFlag{ 118 + Name: "quiet", 119 + Aliases: []string{"q"}, 120 + Usage: "Only display warnings and errors", 118 121 }, 119 - cli.StringFlag{ 120 - Name: "tempdir, t", 121 - Value: os.TempDir(), 122 - Usage: "Temporary dir path", 122 + &cli.StringFlag{ 123 + Name: "tempdir", 124 + Aliases: []string{"t"}, 125 + Value: os.TempDir(), 126 + Usage: "Temporary dir path", 123 127 }, 124 - cli.StringFlag{ 125 - Name: "database, d", 126 - Usage: "Specify the database SQL syntax", 128 + &cli.StringFlag{ 129 + Name: "database", 130 + Aliases: []string{"d"}, 131 + Usage: "Specify the database SQL syntax", 127 132 }, 128 - cli.BoolFlag{ 129 - Name: "skip-repository, R", 130 - Usage: "Skip the repository dumping", 133 + &cli.BoolFlag{ 134 + Name: "skip-repository", 135 + Aliases: []string{"R"}, 136 + Usage: "Skip the repository dumping", 131 137 }, 132 - cli.BoolFlag{ 133 - Name: "skip-log, L", 134 - Usage: "Skip the log dumping", 138 + &cli.BoolFlag{ 139 + Name: "skip-log", 140 + Aliases: []string{"L"}, 141 + Usage: "Skip the log dumping", 135 142 }, 136 - cli.BoolFlag{ 143 + &cli.BoolFlag{ 137 144 Name: "skip-custom-dir", 138 145 Usage: "Skip custom directory", 139 146 }, 140 - cli.BoolFlag{ 147 + &cli.BoolFlag{ 141 148 Name: "skip-lfs-data", 142 149 Usage: "Skip LFS data", 143 150 }, 144 - cli.BoolFlag{ 151 + &cli.BoolFlag{ 145 152 Name: "skip-attachment-data", 146 153 Usage: "Skip attachment data", 147 154 }, 148 - cli.BoolFlag{ 155 + &cli.BoolFlag{ 149 156 Name: "skip-package-data", 150 157 Usage: "Skip package data", 151 158 }, 152 - cli.BoolFlag{ 159 + &cli.BoolFlag{ 153 160 Name: "skip-index", 154 161 Usage: "Skip bleve index data", 155 162 }, 156 - cli.GenericFlag{ 163 + &cli.GenericFlag{ 157 164 Name: "type", 158 165 Value: outputTypeEnum, 159 166 Usage: fmt.Sprintf("Dump output format: %s", outputTypeEnum.Join()),
+15 -14
cmd/dump_repo.go
··· 19 19 "code.gitea.io/gitea/services/convert" 20 20 "code.gitea.io/gitea/services/migrations" 21 21 22 - "github.com/urfave/cli" 22 + "github.com/urfave/cli/v2" 23 23 ) 24 24 25 25 // CmdDumpRepository represents the available dump repository sub-command. 26 - var CmdDumpRepository = cli.Command{ 26 + var CmdDumpRepository = &cli.Command{ 27 27 Name: "dump-repo", 28 28 Usage: "Dump the repository from git/github/gitea/gitlab", 29 29 Description: "This is a command for dumping the repository data.", 30 30 Action: runDumpRepository, 31 31 Flags: []cli.Flag{ 32 - cli.StringFlag{ 32 + &cli.StringFlag{ 33 33 Name: "git_service", 34 34 Value: "", 35 35 Usage: "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored.", 36 36 }, 37 - cli.StringFlag{ 38 - Name: "repo_dir, r", 39 - Value: "./data", 40 - Usage: "Repository dir path to store the data", 37 + &cli.StringFlag{ 38 + Name: "repo_dir", 39 + Aliases: []string{"r"}, 40 + Value: "./data", 41 + Usage: "Repository dir path to store the data", 41 42 }, 42 - cli.StringFlag{ 43 + &cli.StringFlag{ 43 44 Name: "clone_addr", 44 45 Value: "", 45 46 Usage: "The URL will be clone, currently could be a git/github/gitea/gitlab http/https URL", 46 47 }, 47 - cli.StringFlag{ 48 + &cli.StringFlag{ 48 49 Name: "auth_username", 49 50 Value: "", 50 51 Usage: "The username to visit the clone_addr", 51 52 }, 52 - cli.StringFlag{ 53 + &cli.StringFlag{ 53 54 Name: "auth_password", 54 55 Value: "", 55 56 Usage: "The password to visit the clone_addr", 56 57 }, 57 - cli.StringFlag{ 58 + &cli.StringFlag{ 58 59 Name: "auth_token", 59 60 Value: "", 60 61 Usage: "The personal token to visit the clone_addr", 61 62 }, 62 - cli.StringFlag{ 63 + &cli.StringFlag{ 63 64 Name: "owner_name", 64 65 Value: "", 65 66 Usage: "The data will be stored on a directory with owner name if not empty", 66 67 }, 67 - cli.StringFlag{ 68 + &cli.StringFlag{ 68 69 Name: "repo_name", 69 70 Value: "", 70 71 Usage: "The data will be stored on a directory with repository name if not empty", 71 72 }, 72 - cli.StringFlag{ 73 + &cli.StringFlag{ 73 74 Name: "units", 74 75 Value: "", 75 76 Usage: `Which items will be migrated, one or more units should be separated as comma.
+27 -23
cmd/embedded.go
··· 19 19 "code.gitea.io/gitea/modules/util" 20 20 21 21 "github.com/gobwas/glob" 22 - "github.com/urfave/cli" 22 + "github.com/urfave/cli/v2" 23 23 ) 24 24 25 25 // CmdEmbedded represents the available extract sub-command. 26 26 var ( 27 - CmdEmbedded = cli.Command{ 27 + CmdEmbedded = &cli.Command{ 28 28 Name: "embedded", 29 29 Usage: "Extract embedded resources", 30 30 Description: "A command for extracting embedded resources, like templates and images", 31 - Subcommands: []cli.Command{ 31 + Subcommands: []*cli.Command{ 32 32 subcmdList, 33 33 subcmdView, 34 34 subcmdExtract, 35 35 }, 36 36 } 37 37 38 - subcmdList = cli.Command{ 38 + subcmdList = &cli.Command{ 39 39 Name: "list", 40 40 Usage: "List files matching the given pattern", 41 41 Action: runList, 42 42 Flags: []cli.Flag{ 43 - cli.BoolFlag{ 44 - Name: "include-vendored,vendor", 45 - Usage: "Include files under public/vendor as well", 43 + &cli.BoolFlag{ 44 + Name: "include-vendored", 45 + Aliases: []string{"vendor"}, 46 + Usage: "Include files under public/vendor as well", 46 47 }, 47 48 }, 48 49 } 49 50 50 - subcmdView = cli.Command{ 51 + subcmdView = &cli.Command{ 51 52 Name: "view", 52 53 Usage: "View a file matching the given pattern", 53 54 Action: runView, 54 55 Flags: []cli.Flag{ 55 - cli.BoolFlag{ 56 - Name: "include-vendored,vendor", 57 - Usage: "Include files under public/vendor as well", 56 + &cli.BoolFlag{ 57 + Name: "include-vendored", 58 + Aliases: []string{"vendor"}, 59 + Usage: "Include files under public/vendor as well", 58 60 }, 59 61 }, 60 62 } 61 63 62 - subcmdExtract = cli.Command{ 64 + subcmdExtract = &cli.Command{ 63 65 Name: "extract", 64 66 Usage: "Extract resources", 65 67 Action: runExtract, 66 68 Flags: []cli.Flag{ 67 - cli.BoolFlag{ 68 - Name: "include-vendored,vendor", 69 - Usage: "Include files under public/vendor as well", 69 + &cli.BoolFlag{ 70 + Name: "include-vendored", 71 + Aliases: []string{"vendor"}, 72 + Usage: "Include files under public/vendor as well", 70 73 }, 71 - cli.BoolFlag{ 74 + &cli.BoolFlag{ 72 75 Name: "overwrite", 73 76 Usage: "Overwrite files if they already exist", 74 77 }, 75 - cli.BoolFlag{ 78 + &cli.BoolFlag{ 76 79 Name: "rename", 77 80 Usage: "Rename files as {name}.bak if they already exist (overwrites previous .bak)", 78 81 }, 79 - cli.BoolFlag{ 82 + &cli.BoolFlag{ 80 83 Name: "custom", 81 84 Usage: "Extract to the 'custom' directory as per app.ini", 82 85 }, 83 - cli.StringFlag{ 84 - Name: "destination,dest-dir", 85 - Usage: "Extract to the specified directory", 86 + &cli.StringFlag{ 87 + Name: "destination", 88 + Aliases: []string{"dest-dir"}, 89 + Usage: "Extract to the specified directory", 86 90 }, 87 91 }, 88 92 } ··· 99 103 func initEmbeddedExtractor(c *cli.Context) error { 100 104 setupConsoleLogger(log.ERROR, log.CanColorStderr, os.Stderr) 101 105 102 - patterns, err := compileCollectPatterns(c.Args()) 106 + patterns, err := compileCollectPatterns(c.Args().Slice()) 103 107 if err != nil { 104 108 return err 105 109 } ··· 175 179 return err 176 180 } 177 181 178 - if len(c.Args()) == 0 { 182 + if c.NArg() == 0 { 179 183 return fmt.Errorf("a list of pattern of files to extract is mandatory (e.g. '**' for all)") 180 184 } 181 185
+8 -8
cmd/generate.go
··· 11 11 "code.gitea.io/gitea/modules/generate" 12 12 13 13 "github.com/mattn/go-isatty" 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 17 var ( 18 18 // CmdGenerate represents the available generate sub-command. 19 - CmdGenerate = cli.Command{ 19 + CmdGenerate = &cli.Command{ 20 20 Name: "generate", 21 21 Usage: "Command line interface for running generators", 22 - Subcommands: []cli.Command{ 22 + Subcommands: []*cli.Command{ 23 23 subcmdSecret, 24 24 }, 25 25 } 26 26 27 - subcmdSecret = cli.Command{ 27 + subcmdSecret = &cli.Command{ 28 28 Name: "secret", 29 29 Usage: "Generate a secret token", 30 - Subcommands: []cli.Command{ 30 + Subcommands: []*cli.Command{ 31 31 microcmdGenerateInternalToken, 32 32 microcmdGenerateLfsJwtSecret, 33 33 microcmdGenerateSecretKey, 34 34 }, 35 35 } 36 36 37 - microcmdGenerateInternalToken = cli.Command{ 37 + microcmdGenerateInternalToken = &cli.Command{ 38 38 Name: "INTERNAL_TOKEN", 39 39 Usage: "Generate a new INTERNAL_TOKEN", 40 40 Action: runGenerateInternalToken, 41 41 } 42 42 43 - microcmdGenerateLfsJwtSecret = cli.Command{ 43 + microcmdGenerateLfsJwtSecret = &cli.Command{ 44 44 Name: "JWT_SECRET", 45 45 Aliases: []string{"LFS_JWT_SECRET"}, 46 46 Usage: "Generate a new JWT_SECRET", 47 47 Action: runGenerateLfsJwtSecret, 48 48 } 49 49 50 - microcmdGenerateSecretKey = cli.Command{ 50 + microcmdGenerateSecretKey = &cli.Command{ 51 51 Name: "SECRET_KEY", 52 52 Usage: "Generate a new SECRET_KEY", 53 53 Action: runGenerateSecretKey,
+11 -11
cmd/hook.go
··· 20 20 repo_module "code.gitea.io/gitea/modules/repository" 21 21 "code.gitea.io/gitea/modules/setting" 22 22 23 - "github.com/urfave/cli" 23 + "github.com/urfave/cli/v2" 24 24 ) 25 25 26 26 const ( ··· 29 29 30 30 var ( 31 31 // CmdHook represents the available hooks sub-command. 32 - CmdHook = cli.Command{ 32 + CmdHook = &cli.Command{ 33 33 Name: "hook", 34 34 Usage: "Delegate commands to corresponding Git hooks", 35 35 Description: "This should only be called by Git", 36 36 Before: PrepareConsoleLoggerLevel(log.FATAL), 37 - Subcommands: []cli.Command{ 37 + Subcommands: []*cli.Command{ 38 38 subcmdHookPreReceive, 39 39 subcmdHookUpdate, 40 40 subcmdHookPostReceive, ··· 42 42 }, 43 43 } 44 44 45 - subcmdHookPreReceive = cli.Command{ 45 + subcmdHookPreReceive = &cli.Command{ 46 46 Name: "pre-receive", 47 47 Usage: "Delegate pre-receive Git hook", 48 48 Description: "This command should only be called by Git", 49 49 Action: runHookPreReceive, 50 50 Flags: []cli.Flag{ 51 - cli.BoolFlag{ 51 + &cli.BoolFlag{ 52 52 Name: "debug", 53 53 }, 54 54 }, 55 55 } 56 - subcmdHookUpdate = cli.Command{ 56 + subcmdHookUpdate = &cli.Command{ 57 57 Name: "update", 58 58 Usage: "Delegate update Git hook", 59 59 Description: "This command should only be called by Git", 60 60 Action: runHookUpdate, 61 61 Flags: []cli.Flag{ 62 - cli.BoolFlag{ 62 + &cli.BoolFlag{ 63 63 Name: "debug", 64 64 }, 65 65 }, 66 66 } 67 - subcmdHookPostReceive = cli.Command{ 67 + subcmdHookPostReceive = &cli.Command{ 68 68 Name: "post-receive", 69 69 Usage: "Delegate post-receive Git hook", 70 70 Description: "This command should only be called by Git", 71 71 Action: runHookPostReceive, 72 72 Flags: []cli.Flag{ 73 - cli.BoolFlag{ 73 + &cli.BoolFlag{ 74 74 Name: "debug", 75 75 }, 76 76 }, 77 77 } 78 78 // Note: new hook since git 2.29 79 - subcmdHookProcReceive = cli.Command{ 79 + subcmdHookProcReceive = &cli.Command{ 80 80 Name: "proc-receive", 81 81 Usage: "Delegate proc-receive Git hook", 82 82 Description: "This command should only be called by Git", 83 83 Action: runHookProcReceive, 84 84 Flags: []cli.Flag{ 85 - cli.BoolFlag{ 85 + &cli.BoolFlag{ 86 86 Name: "debug", 87 87 }, 88 88 },
+23 -19
cmd/keys.go
··· 11 11 "code.gitea.io/gitea/modules/log" 12 12 "code.gitea.io/gitea/modules/private" 13 13 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 17 // CmdKeys represents the available keys sub-command 18 - var CmdKeys = cli.Command{ 18 + var CmdKeys = &cli.Command{ 19 19 Name: "keys", 20 20 Usage: "This command queries the Gitea database to get the authorized command for a given ssh key fingerprint", 21 21 Before: PrepareConsoleLoggerLevel(log.FATAL), 22 22 Action: runKeys, 23 23 Flags: []cli.Flag{ 24 - cli.StringFlag{ 25 - Name: "expected, e", 26 - Value: "git", 27 - Usage: "Expected user for whom provide key commands", 24 + &cli.StringFlag{ 25 + Name: "expected", 26 + Aliases: []string{"e"}, 27 + Value: "git", 28 + Usage: "Expected user for whom provide key commands", 28 29 }, 29 - cli.StringFlag{ 30 - Name: "username, u", 31 - Value: "", 32 - Usage: "Username trying to log in by SSH", 30 + &cli.StringFlag{ 31 + Name: "username", 32 + Aliases: []string{"u"}, 33 + Value: "", 34 + Usage: "Username trying to log in by SSH", 33 35 }, 34 - cli.StringFlag{ 35 - Name: "type, t", 36 - Value: "", 37 - Usage: "Type of the SSH key provided to the SSH Server (requires content to be provided too)", 36 + &cli.StringFlag{ 37 + Name: "type", 38 + Aliases: []string{"t"}, 39 + Value: "", 40 + Usage: "Type of the SSH key provided to the SSH Server (requires content to be provided too)", 38 41 }, 39 - cli.StringFlag{ 40 - Name: "content, k", 41 - Value: "", 42 - Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)", 42 + &cli.StringFlag{ 43 + Name: "content", 44 + Aliases: []string{"k"}, 45 + Value: "", 46 + Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)", 43 47 }, 44 48 }, 45 49 } ··· 73 77 if extra.Error != nil { 74 78 return extra.Error 75 79 } 76 - fmt.Println(strings.TrimSpace(authorizedString)) 80 + _, _ = fmt.Fprintln(c.App.Writer, strings.TrimSpace(authorizedString)) 77 81 return nil 78 82 }
+1 -1
cmd/mailer.go
··· 9 9 "code.gitea.io/gitea/modules/private" 10 10 "code.gitea.io/gitea/modules/setting" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 15 func runSendMail(c *cli.Context) error {
+196
cmd/main.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package cmd 5 + 6 + import ( 7 + "fmt" 8 + "os" 9 + "reflect" 10 + "strings" 11 + 12 + "code.gitea.io/gitea/modules/log" 13 + "code.gitea.io/gitea/modules/setting" 14 + 15 + "github.com/urfave/cli/v2" 16 + ) 17 + 18 + // cmdHelp is our own help subcommand with more information 19 + func cmdHelp() *cli.Command { 20 + c := &cli.Command{ 21 + Name: "help", 22 + Aliases: []string{"h"}, 23 + Usage: "Shows a list of commands or help for one command", 24 + ArgsUsage: "[command]", 25 + Action: func(c *cli.Context) (err error) { 26 + args := c.Args() 27 + if args.Present() { 28 + err = cli.ShowCommandHelp(c, args.First()) 29 + } else { 30 + err = cli.ShowAppHelp(c) 31 + } 32 + _, _ = fmt.Fprintf(c.App.Writer, ` 33 + DEFAULT CONFIGURATION: 34 + AppPath: %s 35 + WorkPath: %s 36 + CustomPath: %s 37 + ConfigFile: %s 38 + 39 + `, setting.AppPath, setting.AppWorkPath, setting.CustomPath, setting.CustomConf) 40 + return err 41 + }, 42 + } 43 + return c 44 + } 45 + 46 + var helpFlag = cli.HelpFlag 47 + 48 + func init() { 49 + // cli.HelpFlag = nil TODO: after https://github.com/urfave/cli/issues/1794 we can use this 50 + } 51 + 52 + func appGlobalFlags() []cli.Flag { 53 + return []cli.Flag{ 54 + // make the builtin flags at the top 55 + helpFlag, 56 + cli.VersionFlag, 57 + 58 + // shared configuration flags, they are for global and for each sub-command at the same time 59 + // eg: such command is valid: "./gitea --config /tmp/app.ini web --config /tmp/app.ini", while it's discouraged indeed 60 + // keep in mind that the short flags like "-C", "-c" and "-w" are globally polluted, they can't be used for sub-commands anymore. 61 + &cli.StringFlag{ 62 + Name: "custom-path", 63 + Aliases: []string{"C"}, 64 + Usage: "Set custom path (defaults to '{WorkPath}/custom')", 65 + }, 66 + &cli.StringFlag{ 67 + Name: "config", 68 + Aliases: []string{"c"}, 69 + Value: setting.CustomConf, 70 + Usage: "Set custom config file (defaults to '{WorkPath}/custom/conf/app.ini')", 71 + }, 72 + &cli.StringFlag{ 73 + Name: "work-path", 74 + Aliases: []string{"w"}, 75 + Usage: "Set Gitea's working path (defaults to the Gitea's binary directory)", 76 + }, 77 + } 78 + } 79 + 80 + func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) { 81 + command.Flags = append(append([]cli.Flag{}, globalFlags...), command.Flags...) 82 + command.Action = prepareWorkPathAndCustomConf(command.Action) 83 + command.HideHelp = true 84 + if command.Name != "help" { 85 + command.Subcommands = append(command.Subcommands, cmdHelp()) 86 + } 87 + for i := range command.Subcommands { 88 + prepareSubcommandWithConfig(command.Subcommands[i], globalFlags) 89 + } 90 + } 91 + 92 + // prepareWorkPathAndCustomConf wraps the Action to prepare the work path and custom config 93 + // It can't use "Before", because each level's sub-command's Before will be called one by one, so the "init" would be done multiple times 94 + func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context) error { 95 + return func(ctx *cli.Context) error { 96 + var args setting.ArgWorkPathAndCustomConf 97 + ctxLineage := ctx.Lineage() 98 + for i := len(ctxLineage) - 1; i >= 0; i-- { 99 + curCtx := ctxLineage[i] 100 + if curCtx.IsSet("work-path") && args.WorkPath == "" { 101 + args.WorkPath = curCtx.String("work-path") 102 + } 103 + if curCtx.IsSet("custom-path") && args.CustomPath == "" { 104 + args.CustomPath = curCtx.String("custom-path") 105 + } 106 + if curCtx.IsSet("config") && args.CustomConf == "" { 107 + args.CustomConf = curCtx.String("config") 108 + } 109 + } 110 + setting.InitWorkPathAndCommonConfig(os.Getenv, args) 111 + if ctx.Bool("help") || action == nil { 112 + // the default behavior of "urfave/cli": "nil action" means "show help" 113 + return cmdHelp().Action(ctx) 114 + } 115 + return action(ctx) 116 + } 117 + } 118 + 119 + func reflectGet(v any, fieldName string) any { 120 + e := reflect.ValueOf(v).Elem() 121 + return e.FieldByName(fieldName).Interface() 122 + } 123 + 124 + // https://cli.urfave.org/migrate-v1-to-v2/#flag-aliases-are-done-differently 125 + // Sadly v2 doesn't warn you if a comma is in the name. (https://github.com/urfave/cli/issues/1103) 126 + func checkCommandFlags(c any) bool { 127 + var cmds []*cli.Command 128 + if app, ok := c.(*cli.App); ok { 129 + cmds = app.Commands 130 + } else { 131 + cmds = c.(*cli.Command).Subcommands 132 + } 133 + ok := true 134 + for _, cmd := range cmds { 135 + for _, flag := range cmd.Flags { 136 + flagName := reflectGet(flag, "Name").(string) 137 + if strings.Contains(flagName, ",") { 138 + ok = false 139 + log.Error("cli.Flag can't have comma in its Name: %q, use Aliases instead", flagName) 140 + } 141 + } 142 + if !checkCommandFlags(cmd) { 143 + ok = false 144 + } 145 + } 146 + return ok 147 + } 148 + 149 + func NewMainApp() *cli.App { 150 + app := cli.NewApp() 151 + app.EnableBashCompletion = true 152 + 153 + // these sub-commands need to use config file 154 + subCmdWithConfig := []*cli.Command{ 155 + CmdWeb, 156 + CmdServ, 157 + CmdHook, 158 + CmdDump, 159 + CmdAdmin, 160 + CmdMigrate, 161 + CmdKeys, 162 + CmdConvert, 163 + CmdDoctor, 164 + CmdManager, 165 + CmdEmbedded, 166 + CmdMigrateStorage, 167 + CmdDumpRepository, 168 + CmdRestoreRepository, 169 + CmdActions, 170 + cmdHelp(), // the "help" sub-command was used to show the more information for "work path" and "custom config" 171 + } 172 + 173 + // these sub-commands do not need the config file, and they do not depend on any path or environment variable. 174 + subCmdStandalone := []*cli.Command{ 175 + CmdCert, 176 + CmdGenerate, 177 + CmdDocs, 178 + } 179 + 180 + app.DefaultCommand = CmdWeb.Name 181 + 182 + globalFlags := appGlobalFlags() 183 + app.Flags = append(app.Flags, globalFlags...) 184 + app.HideHelp = true // use our own help action to show helps (with more information like default config) 185 + app.Before = PrepareConsoleLoggerLevel(log.INFO) 186 + for i := range subCmdWithConfig { 187 + prepareSubcommandWithConfig(subCmdWithConfig[i], globalFlags) 188 + } 189 + app.Commands = append(app.Commands, subCmdWithConfig...) 190 + app.Commands = append(app.Commands, subCmdStandalone...) 191 + 192 + if !checkCommandFlags(app) { 193 + panic("some flags are incorrect") // this is a runtime check to help developers 194 + } 195 + return app 196 + }
+115
cmd/main_test.go
··· 4 4 package cmd 5 5 6 6 import ( 7 + "fmt" 8 + "os" 9 + "path/filepath" 10 + "strings" 7 11 "testing" 8 12 9 13 "code.gitea.io/gitea/models/unittest" 14 + "code.gitea.io/gitea/modules/setting" 15 + 16 + "github.com/stretchr/testify/assert" 17 + "github.com/urfave/cli/v2" 10 18 ) 11 19 12 20 func TestMain(m *testing.M) { ··· 14 22 GiteaRootPath: "..", 15 23 }) 16 24 } 25 + 26 + func makePathOutput(workPath, customPath, customConf string) string { 27 + return fmt.Sprintf("WorkPath=%s\nCustomPath=%s\nCustomConf=%s", workPath, customPath, customConf) 28 + } 29 + 30 + func newTestApp() *cli.App { 31 + app := NewMainApp() 32 + testCmd := &cli.Command{ 33 + Name: "test-cmd", 34 + Action: func(ctx *cli.Context) error { 35 + _, _ = fmt.Fprint(app.Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf)) 36 + return nil 37 + }, 38 + } 39 + prepareSubcommandWithConfig(testCmd, appGlobalFlags()) 40 + app.Commands = append(app.Commands, testCmd) 41 + app.DefaultCommand = testCmd.Name 42 + return app 43 + } 44 + 45 + func TestCliCmd(t *testing.T) { 46 + defaultWorkPath := filepath.Dir(setting.AppPath) 47 + defaultCustomPath := filepath.Join(defaultWorkPath, "custom") 48 + defaultCustomConf := filepath.Join(defaultCustomPath, "conf/app.ini") 49 + 50 + cli.CommandHelpTemplate = "(command help template)" 51 + cli.AppHelpTemplate = "(app help template)" 52 + cli.SubcommandHelpTemplate = "(subcommand help template)" 53 + 54 + cases := []struct { 55 + env map[string]string 56 + cmd string 57 + exp string 58 + }{ 59 + // main command help 60 + { 61 + cmd: "./gitea help", 62 + exp: "DEFAULT CONFIGURATION:", 63 + }, 64 + 65 + // parse paths 66 + { 67 + cmd: "./gitea test-cmd", 68 + exp: makePathOutput(defaultWorkPath, defaultCustomPath, defaultCustomConf), 69 + }, 70 + { 71 + cmd: "./gitea -c /tmp/app.ini test-cmd", 72 + exp: makePathOutput(defaultWorkPath, defaultCustomPath, "/tmp/app.ini"), 73 + }, 74 + { 75 + cmd: "./gitea test-cmd -c /tmp/app.ini", 76 + exp: makePathOutput(defaultWorkPath, defaultCustomPath, "/tmp/app.ini"), 77 + }, 78 + { 79 + env: map[string]string{"GITEA_WORK_DIR": "/tmp"}, 80 + cmd: "./gitea test-cmd", 81 + exp: makePathOutput("/tmp", "/tmp/custom", "/tmp/custom/conf/app.ini"), 82 + }, 83 + { 84 + env: map[string]string{"GITEA_WORK_DIR": "/tmp"}, 85 + cmd: "./gitea test-cmd --work-path /tmp/other", 86 + exp: makePathOutput("/tmp/other", "/tmp/other/custom", "/tmp/other/custom/conf/app.ini"), 87 + }, 88 + { 89 + env: map[string]string{"GITEA_WORK_DIR": "/tmp"}, 90 + cmd: "./gitea test-cmd --config /tmp/app-other.ini", 91 + exp: makePathOutput("/tmp", "/tmp/custom", "/tmp/app-other.ini"), 92 + }, 93 + } 94 + 95 + app := newTestApp() 96 + var envBackup []string 97 + for _, s := range os.Environ() { 98 + if strings.HasPrefix(s, "GITEA_") && strings.Contains(s, "=") { 99 + envBackup = append(envBackup, s) 100 + } 101 + } 102 + clearGiteaEnv := func() { 103 + for _, s := range os.Environ() { 104 + if strings.HasPrefix(s, "GITEA_") { 105 + _ = os.Unsetenv(s) 106 + } 107 + } 108 + } 109 + defer func() { 110 + clearGiteaEnv() 111 + for _, s := range envBackup { 112 + k, v, _ := strings.Cut(s, "=") 113 + _ = os.Setenv(k, v) 114 + } 115 + }() 116 + 117 + for _, c := range cases { 118 + clearGiteaEnv() 119 + for k, v := range c.env { 120 + _ = os.Setenv(k, v) 121 + } 122 + args := strings.Split(c.cmd, " ") // for test only, "split" is good enough 123 + out := new(strings.Builder) 124 + app.Writer = out 125 + err := app.Run(args) 126 + assert.NoError(t, err, c.cmd) 127 + assert.NotEmpty(t, c.exp, c.cmd) 128 + outStr := out.String() 129 + assert.Contains(t, outStr, c.exp, c.cmd) 130 + } 131 + }
+20 -20
cmd/manager.go
··· 9 9 10 10 "code.gitea.io/gitea/modules/private" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 15 var ( 16 16 // CmdManager represents the manager command 17 - CmdManager = cli.Command{ 17 + CmdManager = &cli.Command{ 18 18 Name: "manager", 19 19 Usage: "Manage the running gitea process", 20 20 Description: "This is a command for managing the running gitea process", 21 - Subcommands: []cli.Command{ 21 + Subcommands: []*cli.Command{ 22 22 subcmdShutdown, 23 23 subcmdRestart, 24 24 subcmdReloadTemplates, ··· 27 27 subCmdProcesses, 28 28 }, 29 29 } 30 - subcmdShutdown = cli.Command{ 30 + subcmdShutdown = &cli.Command{ 31 31 Name: "shutdown", 32 32 Usage: "Gracefully shutdown the running process", 33 33 Flags: []cli.Flag{ 34 - cli.BoolFlag{ 34 + &cli.BoolFlag{ 35 35 Name: "debug", 36 36 }, 37 37 }, 38 38 Action: runShutdown, 39 39 } 40 - subcmdRestart = cli.Command{ 40 + subcmdRestart = &cli.Command{ 41 41 Name: "restart", 42 42 Usage: "Gracefully restart the running process - (not implemented for windows servers)", 43 43 Flags: []cli.Flag{ 44 - cli.BoolFlag{ 44 + &cli.BoolFlag{ 45 45 Name: "debug", 46 46 }, 47 47 }, 48 48 Action: runRestart, 49 49 } 50 - subcmdReloadTemplates = cli.Command{ 50 + subcmdReloadTemplates = &cli.Command{ 51 51 Name: "reload-templates", 52 52 Usage: "Reload template files in the running process", 53 53 Flags: []cli.Flag{ 54 - cli.BoolFlag{ 54 + &cli.BoolFlag{ 55 55 Name: "debug", 56 56 }, 57 57 }, 58 58 Action: runReloadTemplates, 59 59 } 60 - subcmdFlushQueues = cli.Command{ 60 + subcmdFlushQueues = &cli.Command{ 61 61 Name: "flush-queues", 62 62 Usage: "Flush queues in the running process", 63 63 Action: runFlushQueues, 64 64 Flags: []cli.Flag{ 65 - cli.DurationFlag{ 65 + &cli.DurationFlag{ 66 66 Name: "timeout", 67 67 Value: 60 * time.Second, 68 68 Usage: "Timeout for the flushing process", 69 69 }, 70 - cli.BoolFlag{ 70 + &cli.BoolFlag{ 71 71 Name: "non-blocking", 72 72 Usage: "Set to true to not wait for flush to complete before returning", 73 73 }, 74 - cli.BoolFlag{ 74 + &cli.BoolFlag{ 75 75 Name: "debug", 76 76 }, 77 77 }, 78 78 } 79 - subCmdProcesses = cli.Command{ 79 + subCmdProcesses = &cli.Command{ 80 80 Name: "processes", 81 81 Usage: "Display running processes within the current process", 82 82 Action: runProcesses, 83 83 Flags: []cli.Flag{ 84 - cli.BoolFlag{ 84 + &cli.BoolFlag{ 85 85 Name: "debug", 86 86 }, 87 - cli.BoolFlag{ 87 + &cli.BoolFlag{ 88 88 Name: "flat", 89 89 Usage: "Show processes as flat table rather than as tree", 90 90 }, 91 - cli.BoolFlag{ 91 + &cli.BoolFlag{ 92 92 Name: "no-system", 93 93 Usage: "Do not show system processes", 94 94 }, 95 - cli.BoolFlag{ 95 + &cli.BoolFlag{ 96 96 Name: "stacktraces", 97 97 Usage: "Show stacktraces", 98 98 }, 99 - cli.BoolFlag{ 99 + &cli.BoolFlag{ 100 100 Name: "json", 101 101 Usage: "Output as json", 102 102 }, 103 - cli.StringFlag{ 103 + &cli.StringFlag{ 104 104 Name: "cancel", 105 105 Usage: "Process PID to cancel. (Only available for non-system processes.)", 106 106 },
+94 -61
cmd/manager_logging.go
··· 10 10 "code.gitea.io/gitea/modules/log" 11 11 "code.gitea.io/gitea/modules/private" 12 12 13 - "github.com/urfave/cli" 13 + "github.com/urfave/cli/v2" 14 14 ) 15 15 16 16 var ( 17 17 defaultLoggingFlags = []cli.Flag{ 18 - cli.StringFlag{ 18 + &cli.StringFlag{ 19 19 Name: "logger", 20 20 Usage: `Logger name - will default to "default"`, 21 - }, cli.StringFlag{ 21 + }, 22 + &cli.StringFlag{ 22 23 Name: "writer", 23 24 Usage: "Name of the log writer - will default to mode", 24 - }, cli.StringFlag{ 25 + }, 26 + &cli.StringFlag{ 25 27 Name: "level", 26 28 Usage: "Logging level for the new logger", 27 - }, cli.StringFlag{ 28 - Name: "stacktrace-level, L", 29 - Usage: "Stacktrace logging level", 30 - }, cli.StringFlag{ 31 - Name: "flags, F", 32 - Usage: "Flags for the logger", 33 - }, cli.StringFlag{ 34 - Name: "expression, e", 35 - Usage: "Matching expression for the logger", 36 - }, cli.StringFlag{ 37 - Name: "prefix, p", 38 - Usage: "Prefix for the logger", 39 - }, cli.BoolFlag{ 29 + }, 30 + &cli.StringFlag{ 31 + Name: "stacktrace-level", 32 + Aliases: []string{"L"}, 33 + Usage: "Stacktrace logging level", 34 + }, 35 + &cli.StringFlag{ 36 + Name: "flags", 37 + Aliases: []string{"F"}, 38 + Usage: "Flags for the logger", 39 + }, 40 + &cli.StringFlag{ 41 + Name: "expression", 42 + Aliases: []string{"e"}, 43 + Usage: "Matching expression for the logger", 44 + }, 45 + &cli.StringFlag{ 46 + Name: "prefix", 47 + Aliases: []string{"p"}, 48 + Usage: "Prefix for the logger", 49 + }, 50 + &cli.BoolFlag{ 40 51 Name: "color", 41 52 Usage: "Use color in the logs", 42 - }, cli.BoolFlag{ 53 + }, 54 + &cli.BoolFlag{ 43 55 Name: "debug", 44 56 }, 45 57 } 46 58 47 - subcmdLogging = cli.Command{ 59 + subcmdLogging = &cli.Command{ 48 60 Name: "logging", 49 61 Usage: "Adjust logging commands", 50 - Subcommands: []cli.Command{ 62 + Subcommands: []*cli.Command{ 51 63 { 52 64 Name: "pause", 53 65 Usage: "Pause logging (Gitea will buffer logs up to a certain point and will drop them after that point)", 54 66 Flags: []cli.Flag{ 55 - cli.BoolFlag{ 67 + &cli.BoolFlag{ 56 68 Name: "debug", 57 69 }, 58 70 }, ··· 61 73 Name: "resume", 62 74 Usage: "Resume logging", 63 75 Flags: []cli.Flag{ 64 - cli.BoolFlag{ 76 + &cli.BoolFlag{ 65 77 Name: "debug", 66 78 }, 67 79 }, ··· 70 82 Name: "release-and-reopen", 71 83 Usage: "Cause Gitea to release and re-open files used for logging", 72 84 Flags: []cli.Flag{ 73 - cli.BoolFlag{ 85 + &cli.BoolFlag{ 74 86 Name: "debug", 75 87 }, 76 88 }, ··· 80 92 Usage: "Remove a logger", 81 93 ArgsUsage: "[name] Name of logger to remove", 82 94 Flags: []cli.Flag{ 83 - cli.BoolFlag{ 95 + &cli.BoolFlag{ 84 96 Name: "debug", 85 - }, cli.StringFlag{ 97 + }, &cli.StringFlag{ 86 98 Name: "logger", 87 99 Usage: `Logger name - will default to "default"`, 88 100 }, ··· 91 103 }, { 92 104 Name: "add", 93 105 Usage: "Add a logger", 94 - Subcommands: []cli.Command{ 106 + Subcommands: []*cli.Command{ 95 107 { 96 108 Name: "file", 97 109 Usage: "Add a file logger", 98 110 Flags: append(defaultLoggingFlags, []cli.Flag{ 99 - cli.StringFlag{ 100 - Name: "filename, f", 101 - Usage: "Filename for the logger - this must be set.", 102 - }, cli.BoolTFlag{ 103 - Name: "rotate, r", 104 - Usage: "Rotate logs", 105 - }, cli.Int64Flag{ 106 - Name: "max-size, s", 107 - Usage: "Maximum size in bytes before rotation", 108 - }, cli.BoolTFlag{ 109 - Name: "daily, d", 110 - Usage: "Rotate logs daily", 111 - }, cli.IntFlag{ 112 - Name: "max-days, D", 113 - Usage: "Maximum number of daily logs to keep", 114 - }, cli.BoolTFlag{ 115 - Name: "compress, z", 116 - Usage: "Compress rotated logs", 117 - }, cli.IntFlag{ 118 - Name: "compression-level, Z", 119 - Usage: "Compression level to use", 111 + &cli.StringFlag{ 112 + Name: "filename", 113 + Aliases: []string{"f"}, 114 + Usage: "Filename for the logger - this must be set.", 115 + }, 116 + &cli.BoolFlag{ 117 + Name: "rotate", 118 + Aliases: []string{"r"}, 119 + Usage: "Rotate logs", 120 + }, 121 + &cli.Int64Flag{ 122 + Name: "max-size", 123 + Aliases: []string{"s"}, 124 + Usage: "Maximum size in bytes before rotation", 125 + }, 126 + &cli.BoolFlag{ 127 + Name: "daily", 128 + Aliases: []string{"d"}, 129 + Usage: "Rotate logs daily", 130 + }, 131 + &cli.IntFlag{ 132 + Name: "max-days", 133 + Aliases: []string{"D"}, 134 + Usage: "Maximum number of daily logs to keep", 135 + }, 136 + &cli.BoolFlag{ 137 + Name: "compress", 138 + Aliases: []string{"z"}, 139 + Usage: "Compress rotated logs", 140 + }, 141 + &cli.IntFlag{ 142 + Name: "compression-level", 143 + Aliases: []string{"Z"}, 144 + Usage: "Compression level to use", 120 145 }, 121 146 }...), 122 147 Action: runAddFileLogger, ··· 124 149 Name: "conn", 125 150 Usage: "Add a net conn logger", 126 151 Flags: append(defaultLoggingFlags, []cli.Flag{ 127 - cli.BoolFlag{ 128 - Name: "reconnect-on-message, R", 129 - Usage: "Reconnect to host for every message", 130 - }, cli.BoolFlag{ 131 - Name: "reconnect, r", 132 - Usage: "Reconnect to host when connection is dropped", 133 - }, cli.StringFlag{ 134 - Name: "protocol, P", 135 - Usage: "Set protocol to use: tcp, unix, or udp (defaults to tcp)", 136 - }, cli.StringFlag{ 137 - Name: "address, a", 138 - Usage: "Host address and port to connect to (defaults to :7020)", 152 + &cli.BoolFlag{ 153 + Name: "reconnect-on-message", 154 + Aliases: []string{"R"}, 155 + Usage: "Reconnect to host for every message", 156 + }, 157 + &cli.BoolFlag{ 158 + Name: "reconnect", 159 + Aliases: []string{"r"}, 160 + Usage: "Reconnect to host when connection is dropped", 161 + }, 162 + &cli.StringFlag{ 163 + Name: "protocol", 164 + Aliases: []string{"P"}, 165 + Usage: "Set protocol to use: tcp, unix, or udp (defaults to tcp)", 166 + }, 167 + &cli.StringFlag{ 168 + Name: "address", 169 + Aliases: []string{"a"}, 170 + Usage: "Host address and port to connect to (defaults to :7020)", 139 171 }, 140 172 }...), 141 173 Action: runAddConnLogger, ··· 145 177 Name: "log-sql", 146 178 Usage: "Set LogSQL", 147 179 Flags: []cli.Flag{ 148 - cli.BoolFlag{ 180 + &cli.BoolFlag{ 149 181 Name: "debug", 150 - }, cli.BoolFlag{ 182 + }, 183 + &cli.BoolFlag{ 151 184 Name: "off", 152 185 Usage: "Switch off SQL logging", 153 186 },
+2 -2
cmd/migrate.go
··· 11 11 "code.gitea.io/gitea/modules/log" 12 12 "code.gitea.io/gitea/modules/setting" 13 13 14 - "github.com/urfave/cli" 14 + "github.com/urfave/cli/v2" 15 15 ) 16 16 17 17 // CmdMigrate represents the available migrate sub-command. 18 - var CmdMigrate = cli.Command{ 18 + var CmdMigrate = &cli.Command{ 19 19 Name: "migrate", 20 20 Usage: "Migrate the database", 21 21 Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
+26 -23
cmd/migrate_storage.go
··· 20 20 "code.gitea.io/gitea/modules/setting" 21 21 "code.gitea.io/gitea/modules/storage" 22 22 23 - "github.com/urfave/cli" 23 + "github.com/urfave/cli/v2" 24 24 ) 25 25 26 26 // CmdMigrateStorage represents the available migrate storage sub-command. 27 - var CmdMigrateStorage = cli.Command{ 27 + var CmdMigrateStorage = &cli.Command{ 28 28 Name: "migrate-storage", 29 29 Usage: "Migrate the storage", 30 30 Description: "Copies stored files from storage configured in app.ini to parameter-configured storage", 31 31 Action: runMigrateStorage, 32 32 Flags: []cli.Flag{ 33 - cli.StringFlag{ 34 - Name: "type, t", 35 - Value: "", 36 - Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log'", 33 + &cli.StringFlag{ 34 + Name: "type", 35 + Aliases: []string{"t"}, 36 + Value: "", 37 + Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log'", 37 38 }, 38 - cli.StringFlag{ 39 - Name: "storage, s", 40 - Value: "", 41 - Usage: "New storage type: local (default) or minio", 39 + &cli.StringFlag{ 40 + Name: "storage", 41 + Aliases: []string{"s"}, 42 + Value: "", 43 + Usage: "New storage type: local (default) or minio", 42 44 }, 43 - cli.StringFlag{ 44 - Name: "path, p", 45 - Value: "", 46 - Usage: "New storage placement if store is local (leave blank for default)", 45 + &cli.StringFlag{ 46 + Name: "path", 47 + Aliases: []string{"p"}, 48 + Value: "", 49 + Usage: "New storage placement if store is local (leave blank for default)", 47 50 }, 48 - cli.StringFlag{ 51 + &cli.StringFlag{ 49 52 Name: "minio-endpoint", 50 53 Value: "", 51 54 Usage: "Minio storage endpoint", 52 55 }, 53 - cli.StringFlag{ 56 + &cli.StringFlag{ 54 57 Name: "minio-access-key-id", 55 58 Value: "", 56 59 Usage: "Minio storage accessKeyID", 57 60 }, 58 - cli.StringFlag{ 61 + &cli.StringFlag{ 59 62 Name: "minio-secret-access-key", 60 63 Value: "", 61 64 Usage: "Minio storage secretAccessKey", 62 65 }, 63 - cli.StringFlag{ 66 + &cli.StringFlag{ 64 67 Name: "minio-bucket", 65 68 Value: "", 66 69 Usage: "Minio storage bucket", 67 70 }, 68 - cli.StringFlag{ 71 + &cli.StringFlag{ 69 72 Name: "minio-location", 70 73 Value: "", 71 74 Usage: "Minio storage location to create bucket", 72 75 }, 73 - cli.StringFlag{ 76 + &cli.StringFlag{ 74 77 Name: "minio-base-path", 75 78 Value: "", 76 79 Usage: "Minio storage base path on the bucket", 77 80 }, 78 - cli.BoolFlag{ 81 + &cli.BoolFlag{ 79 82 Name: "minio-use-ssl", 80 83 Usage: "Enable SSL for minio", 81 84 }, 82 - cli.BoolFlag{ 85 + &cli.BoolFlag{ 83 86 Name: "minio-insecure-skip-verify", 84 87 Usage: "Skip SSL verification", 85 88 }, 86 - cli.StringFlag{ 89 + &cli.StringFlag{ 87 90 Name: "minio-checksum-algorithm", 88 91 Value: "", 89 92 Usage: "Minio checksum algorithm (default/md5)",
+11 -10
cmd/restore_repo.go
··· 9 9 "code.gitea.io/gitea/modules/private" 10 10 "code.gitea.io/gitea/modules/setting" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 15 // CmdRestoreRepository represents the available restore a repository sub-command. 16 - var CmdRestoreRepository = cli.Command{ 16 + var CmdRestoreRepository = &cli.Command{ 17 17 Name: "restore-repo", 18 18 Usage: "Restore the repository from disk", 19 19 Description: "This is a command for restoring the repository data.", 20 20 Action: runRestoreRepository, 21 21 Flags: []cli.Flag{ 22 - cli.StringFlag{ 23 - Name: "repo_dir, r", 24 - Value: "./data", 25 - Usage: "Repository dir path to restore from", 22 + &cli.StringFlag{ 23 + Name: "repo_dir", 24 + Aliases: []string{"r"}, 25 + Value: "./data", 26 + Usage: "Repository dir path to restore from", 26 27 }, 27 - cli.StringFlag{ 28 + &cli.StringFlag{ 28 29 Name: "owner_name", 29 30 Value: "", 30 31 Usage: "Restore destination owner name", 31 32 }, 32 - cli.StringFlag{ 33 + &cli.StringFlag{ 33 34 Name: "repo_name", 34 35 Value: "", 35 36 Usage: "Restore destination repository name", 36 37 }, 37 - cli.StringFlag{ 38 + &cli.StringFlag{ 38 39 Name: "units", 39 40 Value: "", 40 41 Usage: `Which items will be restored, one or more units should be separated as comma. 41 42 wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`, 42 43 }, 43 - cli.BoolFlag{ 44 + &cli.BoolFlag{ 44 45 Name: "validation", 45 46 Usage: "Sanity check the content of the files before trying to load them", 46 47 },
+10 -10
cmd/serv.go
··· 32 32 33 33 "github.com/golang-jwt/jwt/v5" 34 34 "github.com/kballard/go-shellquote" 35 - "github.com/urfave/cli" 35 + "github.com/urfave/cli/v2" 36 36 ) 37 37 38 38 const ( ··· 40 40 ) 41 41 42 42 // CmdServ represents the available serv sub-command. 43 - var CmdServ = cli.Command{ 43 + var CmdServ = &cli.Command{ 44 44 Name: "serv", 45 45 Usage: "This command should only be called by SSH shell", 46 46 Description: "Serv provides access auth for repositories", 47 47 Before: PrepareConsoleLoggerLevel(log.FATAL), 48 48 Action: runServ, 49 49 Flags: []cli.Flag{ 50 - cli.BoolFlag{ 50 + &cli.BoolFlag{ 51 51 Name: "enable-pprof", 52 52 }, 53 - cli.BoolFlag{ 53 + &cli.BoolFlag{ 54 54 Name: "debug", 55 55 }, 56 56 }, ··· 119 119 } 120 120 _ = private.SSHLog(ctx, true, logMsg) 121 121 } 122 - return cli.NewExitError("", 1) 122 + return cli.Exit("", 1) 123 123 } 124 124 125 125 // handleCliResponseExtra handles the extra response from the cli sub-commands ··· 130 130 _, _ = fmt.Fprintln(os.Stdout, extra.UserMsg) 131 131 } 132 132 if extra.HasError() { 133 - return cli.NewExitError(extra.Error, 1) 133 + return cli.Exit(extra.Error, 1) 134 134 } 135 135 return nil 136 136 } ··· 147 147 return nil 148 148 } 149 149 150 - if len(c.Args()) < 1 { 150 + if c.NArg() < 1 { 151 151 if err := cli.ShowSubcommandHelp(c); err != nil { 152 152 fmt.Printf("error showing subcommand help: %v\n", err) 153 153 } 154 154 return nil 155 155 } 156 156 157 - keys := strings.Split(c.Args()[0], "-") 157 + keys := strings.Split(c.Args().First(), "-") 158 158 if len(keys) != 2 || keys[0] != "key" { 159 - return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args()[0]) 159 + return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First()) 160 160 } 161 161 keyID, err := strconv.ParseInt(keys[1], 10, 64) 162 162 if err != nil { 163 - return fail(ctx, "Key ID parsing error", "Invalid key argument: %s", c.Args()[1]) 163 + return fail(ctx, "Key ID parsing error", "Invalid key argument: %s", c.Args().Get(1)) 164 164 } 165 165 166 166 cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
+18 -15
cmd/web.go
··· 23 23 "code.gitea.io/gitea/routers/install" 24 24 25 25 "github.com/felixge/fgprof" 26 - "github.com/urfave/cli" 26 + "github.com/urfave/cli/v2" 27 27 ) 28 28 29 29 // PIDFile could be set from build tag 30 30 var PIDFile = "/run/gitea.pid" 31 31 32 32 // CmdWeb represents the available web sub-command. 33 - var CmdWeb = cli.Command{ 33 + var CmdWeb = &cli.Command{ 34 34 Name: "web", 35 35 Usage: "Start Gitea web server", 36 36 Description: `Gitea web server is the only thing you need to run, ··· 38 38 Before: PrepareConsoleLoggerLevel(log.INFO), 39 39 Action: runWeb, 40 40 Flags: []cli.Flag{ 41 - cli.StringFlag{ 42 - Name: "port, p", 43 - Value: "3000", 44 - Usage: "Temporary port number to prevent conflict", 41 + &cli.StringFlag{ 42 + Name: "port", 43 + Aliases: []string{"p"}, 44 + Value: "3000", 45 + Usage: "Temporary port number to prevent conflict", 45 46 }, 46 - cli.StringFlag{ 47 + &cli.StringFlag{ 47 48 Name: "install-port", 48 49 Value: "3000", 49 50 Usage: "Temporary port number to run the install page on to prevent conflict", 50 51 }, 51 - cli.StringFlag{ 52 - Name: "pid, P", 53 - Value: PIDFile, 54 - Usage: "Custom pid file path", 52 + &cli.StringFlag{ 53 + Name: "pid", 54 + Aliases: []string{"P"}, 55 + Value: PIDFile, 56 + Usage: "Custom pid file path", 55 57 }, 56 - cli.BoolFlag{ 57 - Name: "quiet, q", 58 - Usage: "Only display Fatal logging errors until logging is set-up", 58 + &cli.BoolFlag{ 59 + Name: "quiet", 60 + Aliases: []string{"q"}, 61 + Usage: "Only display Fatal logging errors until logging is set-up", 59 62 }, 60 - cli.BoolFlag{ 63 + &cli.BoolFlag{ 61 64 Name: "verbose", 62 65 Usage: "Set initial logging to TRACE level until logging is properly set-up", 63 66 },
+14 -14
contrib/backport/backport.go
··· 18 18 "syscall" 19 19 20 20 "github.com/google/go-github/v53/github" 21 - "github.com/urfave/cli" 21 + "github.com/urfave/cli/v2" 22 22 "gopkg.in/yaml.v3" 23 23 ) 24 24 ··· 32 32 app.ArgsUsage = "<PR-to-backport>" 33 33 34 34 app.Flags = []cli.Flag{ 35 - cli.StringFlag{ 35 + &cli.StringFlag{ 36 36 Name: "version", 37 37 Usage: "Version branch to backport on to", 38 38 }, 39 - cli.StringFlag{ 39 + &cli.StringFlag{ 40 40 Name: "upstream", 41 41 Value: "origin", 42 42 Usage: "Upstream remote for the Gitea upstream", 43 43 }, 44 - cli.StringFlag{ 44 + &cli.StringFlag{ 45 45 Name: "release-branch", 46 46 Value: "", 47 47 Usage: "Release branch to backport on. Will default to release/<version>", 48 48 }, 49 - cli.StringFlag{ 49 + &cli.StringFlag{ 50 50 Name: "cherry-pick", 51 51 Usage: "SHA to cherry-pick as backport", 52 52 }, 53 - cli.StringFlag{ 53 + &cli.StringFlag{ 54 54 Name: "backport-branch", 55 55 Usage: "Backport branch to backport on to (default: backport-<pr>-<version>", 56 56 }, 57 - cli.StringFlag{ 57 + &cli.StringFlag{ 58 58 Name: "remote", 59 59 Value: "", 60 60 Usage: "Remote for your fork of the Gitea upstream", 61 61 }, 62 - cli.StringFlag{ 62 + &cli.StringFlag{ 63 63 Name: "fork-user", 64 64 Value: "", 65 65 Usage: "Forked user name on Github", 66 66 }, 67 - cli.BoolFlag{ 67 + &cli.BoolFlag{ 68 68 Name: "no-fetch", 69 69 Usage: "Set this flag to prevent fetch of remote branches", 70 70 }, 71 - cli.BoolFlag{ 71 + &cli.BoolFlag{ 72 72 Name: "no-amend-message", 73 73 Usage: "Set this flag to prevent automatic amendment of the commit message", 74 74 }, 75 - cli.BoolFlag{ 75 + &cli.BoolFlag{ 76 76 Name: "no-push", 77 77 Usage: "Set this flag to prevent pushing the backport up to your fork", 78 78 }, 79 - cli.BoolFlag{ 79 + &cli.BoolFlag{ 80 80 Name: "no-xdg-open", 81 81 Usage: "Set this flag to not use xdg-open to open the PR URL", 82 82 }, 83 - cli.BoolFlag{ 83 + &cli.BoolFlag{ 84 84 Name: "continue", 85 85 Usage: "Set this flag to continue from a git cherry-pick that has broken", 86 86 }, ··· 151 151 152 152 localReleaseBranch := path.Join(upstream, upstreamReleaseBranch) 153 153 154 - args := c.Args() 154 + args := c.Args().Slice() 155 155 if len(args) == 0 && pr == "" { 156 156 return fmt.Errorf("no PR number provided\nProvide a PR number to backport") 157 157 } else if len(args) != 1 && pr == "" {
+5 -5
contrib/environment-to-ini/environment-to-ini.go
··· 9 9 "code.gitea.io/gitea/modules/log" 10 10 "code.gitea.io/gitea/modules/setting" 11 11 12 - "github.com/urfave/cli" 12 + "github.com/urfave/cli/v2" 13 13 ) 14 14 15 15 func main() { ··· 46 46 and "GITEA__LOG_0x2E_CONSOLE__STDERR=false". Other examples can be found 47 47 on the configuration cheat sheet.` 48 48 app.Flags = []cli.Flag{ 49 - cli.StringFlag{ 49 + &cli.StringFlag{ 50 50 Name: "custom-path, C", 51 51 Value: setting.CustomPath, 52 52 Usage: "Custom path file path", 53 53 }, 54 - cli.StringFlag{ 54 + &cli.StringFlag{ 55 55 Name: "config, c", 56 56 Value: setting.CustomConf, 57 57 Usage: "Custom configuration file path", 58 58 }, 59 - cli.StringFlag{ 59 + &cli.StringFlag{ 60 60 Name: "work-path, w", 61 61 Value: setting.AppWorkPath, 62 62 Usage: "Set the gitea working path", 63 63 }, 64 - cli.StringFlag{ 64 + &cli.StringFlag{ 65 65 Name: "out, o", 66 66 Value: "", 67 67 Usage: "Destination file to write to",
+1 -1
custom/conf/app.example.ini
··· 12 12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 13 13 ;; 14 14 ;; These values are environment-dependent but form the basis of a lot of values. They will be 15 - ;; reported as part of the default configuration when running `gitea --help` or on start-up. The order they are emitted there is slightly different but we will list them here in the order they are set-up. 15 + ;; reported as part of the default configuration when running `gitea help` or on start-up. The order they are emitted there is slightly different but we will list them here in the order they are set-up. 16 16 ;; 17 17 ;; - _`AppPath`_: This is the absolute path of the running gitea binary. 18 18 ;; - _`AppWorkPath`_: This refers to "working path" of the `gitea` binary. It is determined by using the first set thing in the following hierarchy:
+1 -1
docs/content/doc/administration/config-cheat-sheet.en-us.md
··· 40 40 ## Default Configuration (non-`app.ini` configuration) 41 41 42 42 These values are environment-dependent but form the basis of a lot of values. They will be 43 - reported as part of the default configuration when running `gitea --help` or on start-up. The order they are emitted there is slightly different but we will list them here in the order they are set-up. 43 + reported as part of the default configuration when running `gitea help` or on start-up. The order they are emitted there is slightly different but we will list them here in the order they are set-up. 44 44 45 45 - _`AppPath`_: This is the absolute path of the running gitea binary. 46 46 - _`AppWorkPath`_: This refers to "working path" of the `gitea` binary. It is determined by using the first set thing in the following hierarchy:
+2 -1
go.mod
··· 98 98 github.com/syndtr/goleveldb v1.0.0 99 99 github.com/tstranex/u2f v1.0.0 100 100 github.com/ulikunitz/xz v0.5.11 101 - github.com/urfave/cli v1.22.14 101 + github.com/urfave/cli/v2 v2.25.7 102 102 github.com/xanzy/go-gitlab v0.86.0 103 103 github.com/xeipuuv/gojsonschema v1.2.0 104 104 github.com/yohcop/openid-go v1.0.1 ··· 278 278 github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect 279 279 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect 280 280 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect 281 + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect 281 282 github.com/zeebo/blake3 v0.2.3 // indirect 282 283 go.etcd.io/bbolt v1.3.7 // indirect 283 284 go.mongodb.org/mongo-driver v1.12.0 // indirect
+4 -3
go.sum
··· 80 80 github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8= 81 81 github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= 82 82 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 83 - github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 84 83 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 85 84 github.com/ClickHouse/ch-go v0.57.0 h1:X/QmUmFhpUvLgPSQb7fWOSi1wvqGn6tJ7w2a59c4xsg= 86 85 github.com/ClickHouse/ch-go v0.57.0/go.mod h1:DR3iBn7OrrDj+KeUp1LbdxLEUDbW+5Qwdl/qkc+PQ+Y= ··· 1162 1161 github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM= 1163 1162 github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= 1164 1163 github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 1165 - github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= 1166 - github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= 1164 + github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= 1165 + github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= 1167 1166 github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 1168 1167 github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 1169 1168 github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= ··· 1198 1197 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= 1199 1198 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 1200 1199 github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 1200 + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= 1201 + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= 1201 1202 github.com/yohcop/openid-go v1.0.1 h1:DPRd3iPO5F6O5zX2e62XpVAbPT6wV51cuucH0z9g3js= 1202 1203 github.com/yohcop/openid-go v1.0.1/go.mod h1:b/AvD03P0KHj4yuihb+VtLD6bYYgsy0zqBzPCRjkCNs= 1203 1204 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
+6 -148
main.go
··· 2 2 // Copyright 2016 The Gitea Authors. All rights reserved. 3 3 // SPDX-License-Identifier: MIT 4 4 5 - // Gitea (git with a cup of tea) is a painless self-hosted Git Service. 6 - package main // import "code.gitea.io/gitea" 5 + package main 7 6 8 7 import ( 9 8 "fmt" ··· 22 21 _ "code.gitea.io/gitea/modules/markup/csv" 23 22 _ "code.gitea.io/gitea/modules/markup/markdown" 24 23 _ "code.gitea.io/gitea/modules/markup/orgmode" 25 - 26 - "github.com/urfave/cli" 27 24 ) 28 25 26 + // these flags will be set by the build flags 29 27 var ( 30 - // Version holds the current Gitea version 31 - Version = "development" 32 - // Tags holds the build tags used 33 - Tags = "" 34 - // MakeVersion holds the current Make version if built with make 35 - MakeVersion = "" 28 + Version = "development" // program version for this build 29 + Tags = "" // the Golang build tags 30 + MakeVersion = "" // "make" program version if built with make 36 31 ) 37 32 38 33 func init() { ··· 41 36 setting.AppStartTime = time.Now().UTC() 42 37 } 43 38 44 - // cmdHelp is our own help subcommand with more information 45 - // test cases: 46 - // ./gitea help 47 - // ./gitea -h 48 - // ./gitea web help 49 - // ./gitea web -h (due to cli lib limitation, this won't call our cmdHelp, so no extra info) 50 - // ./gitea admin 51 - // ./gitea admin help 52 - // ./gitea admin auth help 53 - // ./gitea -c /tmp/app.ini -h 54 - // ./gitea -c /tmp/app.ini help 55 - // ./gitea help -c /tmp/app.ini 56 - // GITEA_WORK_DIR=/tmp ./gitea help 57 - // GITEA_WORK_DIR=/tmp ./gitea help --work-path /tmp/other 58 - // GITEA_WORK_DIR=/tmp ./gitea help --config /tmp/app-other.ini 59 - var cmdHelp = cli.Command{ 60 - Name: "help", 61 - Aliases: []string{"h"}, 62 - Usage: "Shows a list of commands or help for one command", 63 - ArgsUsage: "[command]", 64 - Action: func(c *cli.Context) (err error) { 65 - args := c.Args() 66 - if args.Present() { 67 - err = cli.ShowCommandHelp(c, args.First()) 68 - } else { 69 - err = cli.ShowAppHelp(c) 70 - } 71 - _, _ = fmt.Fprintf(c.App.Writer, ` 72 - DEFAULT CONFIGURATION: 73 - AppPath: %s 74 - WorkPath: %s 75 - CustomPath: %s 76 - ConfigFile: %s 77 - 78 - `, setting.AppPath, setting.AppWorkPath, setting.CustomPath, setting.CustomConf) 79 - return err 80 - }, 81 - } 82 - 83 39 func main() { 84 - app := cli.NewApp() 40 + app := cmd.NewMainApp() 85 41 app.Name = "Gitea" 86 42 app.Usage = "A painless self-hosted Git service" 87 43 app.Description = `By default, Gitea will start serving using the web-server with no argument, which can alternatively be run by running the subcommand "web".` 88 44 app.Version = Version + formatBuiltWith() 89 - app.EnableBashCompletion = true 90 - 91 - // these sub-commands need to use config file 92 - subCmdWithIni := []cli.Command{ 93 - cmd.CmdWeb, 94 - cmd.CmdServ, 95 - cmd.CmdHook, 96 - cmd.CmdDump, 97 - cmd.CmdAdmin, 98 - cmd.CmdMigrate, 99 - cmd.CmdKeys, 100 - cmd.CmdConvert, 101 - cmd.CmdDoctor, 102 - cmd.CmdManager, 103 - cmd.CmdEmbedded, 104 - cmd.CmdMigrateStorage, 105 - cmd.CmdDumpRepository, 106 - cmd.CmdRestoreRepository, 107 - cmd.CmdActions, 108 - cmdHelp, // TODO: the "help" sub-command was used to show the more information for "work path" and "custom config", in the future, it should avoid doing so 109 - } 110 - // these sub-commands do not need the config file, and they do not depend on any path or environment variable. 111 - subCmdStandalone := []cli.Command{ 112 - cmd.CmdCert, 113 - cmd.CmdGenerate, 114 - cmd.CmdDocs, 115 - } 116 - 117 - // shared configuration flags, they are for global and for each sub-command at the same time 118 - // eg: such command is valid: "./gitea --config /tmp/app.ini web --config /tmp/app.ini", while it's discouraged indeed 119 - // keep in mind that the short flags like "-C", "-c" and "-w" are globally polluted, they can't be used for sub-commands anymore. 120 - globalFlags := []cli.Flag{ 121 - cli.HelpFlag, 122 - cli.StringFlag{ 123 - Name: "custom-path, C", 124 - Usage: "Set custom path (defaults to '{WorkPath}/custom')", 125 - }, 126 - cli.StringFlag{ 127 - Name: "config, c", 128 - Value: setting.CustomConf, 129 - Usage: "Set custom config file (defaults to '{WorkPath}/custom/conf/app.ini')", 130 - }, 131 - cli.StringFlag{ 132 - Name: "work-path, w", 133 - Usage: "Set Gitea's working path (defaults to the Gitea's binary directory)", 134 - }, 135 - } 136 - 137 - // Set the default to be equivalent to cmdWeb and add the default flags 138 - app.Flags = append(app.Flags, globalFlags...) 139 - app.Flags = append(app.Flags, cmd.CmdWeb.Flags...) // TODO: the web flags polluted the global flags, they are not really global flags 140 - app.Action = prepareWorkPathAndCustomConf(cmd.CmdWeb.Action) 141 - app.HideHelp = true // use our own help action to show helps (with more information like default config) 142 - app.Before = cmd.PrepareConsoleLoggerLevel(log.INFO) 143 - for i := range subCmdWithIni { 144 - prepareSubcommands(&subCmdWithIni[i], globalFlags) 145 - } 146 - app.Commands = append(app.Commands, subCmdWithIni...) 147 - app.Commands = append(app.Commands, subCmdStandalone...) 148 45 149 46 err := app.Run(os.Args) 150 47 if err != nil { ··· 152 49 } 153 50 154 51 log.GetManager().Close() 155 - } 156 - 157 - func prepareSubcommands(command *cli.Command, defaultFlags []cli.Flag) { 158 - command.Flags = append(command.Flags, defaultFlags...) 159 - command.Action = prepareWorkPathAndCustomConf(command.Action) 160 - command.HideHelp = true 161 - if command.Name != "help" { 162 - command.Subcommands = append(command.Subcommands, cmdHelp) 163 - } 164 - for i := range command.Subcommands { 165 - prepareSubcommands(&command.Subcommands[i], defaultFlags) 166 - } 167 - } 168 - 169 - // prepareWorkPathAndCustomConf wraps the Action to prepare the work path and custom config 170 - // It can't use "Before", because each level's sub-command's Before will be called one by one, so the "init" would be done multiple times 171 - func prepareWorkPathAndCustomConf(action any) func(ctx *cli.Context) error { 172 - return func(ctx *cli.Context) error { 173 - var args setting.ArgWorkPathAndCustomConf 174 - curCtx := ctx 175 - for curCtx != nil { 176 - if curCtx.IsSet("work-path") && args.WorkPath == "" { 177 - args.WorkPath = curCtx.String("work-path") 178 - } 179 - if curCtx.IsSet("custom-path") && args.CustomPath == "" { 180 - args.CustomPath = curCtx.String("custom-path") 181 - } 182 - if curCtx.IsSet("config") && args.CustomConf == "" { 183 - args.CustomConf = curCtx.String("config") 184 - } 185 - curCtx = curCtx.Parent() 186 - } 187 - setting.InitWorkPathAndCommonConfig(os.Getenv, args) 188 - if ctx.Bool("help") || action == nil { 189 - // the default behavior of "urfave/cli": "nil action" means "show help" 190 - return cmdHelp.Action.(func(ctx *cli.Context) error)(ctx) 191 - } 192 - return action.(func(*cli.Context) error)(ctx) 193 - } 194 52 } 195 53 196 54 func formatBuiltWith() string {
+13 -23
tests/integration/cmd_keys_test.go
··· 5 5 6 6 import ( 7 7 "bytes" 8 - "flag" 9 - "io" 10 8 "net/url" 11 - "os" 12 9 "testing" 13 10 14 11 "code.gitea.io/gitea/cmd" 15 12 "code.gitea.io/gitea/modules/setting" 16 13 "code.gitea.io/gitea/modules/util" 17 14 18 - "github.com/urfave/cli" 15 + "github.com/stretchr/testify/assert" 16 + "github.com/urfave/cli/v2" 19 17 ) 20 18 21 19 func Test_CmdKeys(t *testing.T) { ··· 38 36 } 39 37 for _, tt := range tests { 40 38 t.Run(tt.name, func(t *testing.T) { 41 - realStdout := os.Stdout // Backup Stdout 42 - r, w, _ := os.Pipe() 43 - os.Stdout = w 44 - 45 - set := flag.NewFlagSet("keys", 0) 46 - _ = set.Parse(tt.args) 47 - context := cli.NewContext(&cli.App{Writer: os.Stdout}, set, nil) 48 - err := cmd.CmdKeys.Run(context) 49 - if (err != nil) != tt.wantErr { 50 - t.Errorf("CmdKeys.Run() error = %v, wantErr %v", err, tt.wantErr) 51 - } 52 - w.Close() 53 - var buf bytes.Buffer 54 - io.Copy(&buf, r) 55 - commandOutput := buf.String() 56 - if tt.expectedOutput != commandOutput { 57 - t.Errorf("expectedOutput: %#v, commandOutput: %#v", tt.expectedOutput, commandOutput) 39 + out := new(bytes.Buffer) 40 + app := cli.NewApp() 41 + app.Writer = out 42 + app.Commands = []*cli.Command{cmd.CmdKeys} 43 + cmd.CmdKeys.HideHelp = true 44 + err := app.Run(append([]string{"prog"}, tt.args...)) 45 + if tt.wantErr { 46 + assert.Error(t, err) 47 + } else { 48 + assert.NoError(t, err) 58 49 } 59 - // Restore stdout 60 - os.Stdout = realStdout 50 + assert.Equal(t, tt.expectedOutput, out.String()) 61 51 }) 62 52 } 63 53 })