[
  {
    "path": ".gitignore",
    "content": "\ndist/\n.DS_Store\n"
  },
  {
    "path": ".goreleaser.yaml",
    "content": "# This is an example .goreleaser.yml file with some sensible defaults.\n# Make sure to check the documentation at https://goreleaser.com\n\n# The lines below are called `modelines`. See `:help modeline`\n# Feel free to remove those if you don't want/need to use them.\n# yaml-language-server: $schema=https://goreleaser.com/static/schema.json\n# vim: set ts=2 sw=2 tw=0 fo=cnqoj\n\nversion: 2\n\nbefore:\n  hooks:\n    # You may remove this if you don't use go modules.\n    - go mod tidy\n\nbuilds:\n  - env:\n      - CGO_ENABLED=0\n    ldflags:\n      - \"-X 'github.com/mightymoud/sidekick/cmd.version={{.Tag}}'\"\n    goos:\n      - linux\n      - windows\n      - darwin\n\narchives:\n  - format: tar.gz\n    # this name template makes the OS and Arch compatible with the results of `uname`.\n    name_template: >-\n      {{ .ProjectName }}_\n      {{- title .Os }}_\n      {{- if eq .Arch \"amd64\" }}x86_64\n      {{- else if eq .Arch \"386\" }}i386\n      {{- else }}{{ .Arch }}{{ end }}\n      {{- if .Arm }}v{{ .Arm }}{{ end }}\n    # use zip for windows archives\n    format_overrides:\n      - goos: windows\n        format: zip\n\nchangelog:\n  sort: asc\n  filters:\n    exclude:\n      - \"^docs:\"\n      - \"^test:\"\n      - \"^chore:\"\n\nrelease:\n    draft: true\n\n"
  },
  {
    "path": "LICENSE",
    "content": "    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "<div align=\"center\">\n  <div>\n    <img width=\"110px\" src=\"https://emoji.aranja.com/static/emoji-data/img-apple-160/1f91c-1f3fb.png\">\n    <img width=\"110px\" src=\"https://emoji.aranja.com/static/emoji-data/img-apple-160/1f91b-1f3fb.png\">\n  </div>\n\nBare metal to production ready in mins; imagine fly.io on your VPS\n\n  <div>\n    <img width=\"600px\" src=\"/demo/imgs/hero.png\">\n  </div>\n\n![GitHub](https://img.shields.io/github/license/mightymoud/sidekick)\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mightymoud/sidekick)\n![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/mightymoud/sidekick)\n\n</div>\n\n## Features\n\n- 👍 One command VPS setup (docker, traefik, sops, age)\n- 💻 deploy any application from a dockerfile\n- ✊ Zero downtime deployment\n- 🌏 High availability and load balancing\n- 🔒 Zero config SSL Certs\n- ✅ Connect domains or use sslip.io out of the box\n- 🔥 Built in integration with SOPS\n- 🛸 Escape the vendorlock forever\n\n## Motivation\n\nI'm tired of the complexity involved in hosting my side projects. While some platforms, like Fly.io, stand out in the crowded field of Heroku replacements, I believe a simple VPS can be just as effective. That's why I created Sidekick: to make hosting side projects as straightforward, affordable, and production-ready as possible. You'll be surprised how much traffic a $8/month instance on DigitalOcean can handle.\n\n## Installation\n\nUsing brew:\n\n```bash\nbrew install sidekick\n```\n\nNOTE: Sidekick uses `brew` later on to handle installing `sops` on your local. So `brew` is a requirement at this point. Sidekick will throw an error if `brew` is not found. You can install `brew` from [here](https://brew.sh/).\n\n## Usage\n\nSidekick helps you along all the steps of deployment on your VPS. From basic setup to zero downtime deploys, we got you! ✊\n\nFirst you need a VPS with Ubuntu LTS. I recommend DigitalOcean. Hetzner also gets very good reviews. You can host your own silicon too. As long as you have a public IP address you can use Sidekick.\n\nJust make sure the following is true:\n\n- VPS running Ubuntu - LTS recommended\n- SSH Key available on your machine to login to VPS.\n\nThat's it!\n\n### VPS Setup\n\n  <div align=\"center\" >\n    <img width=\"600px\" src=\"/demo/imgs/init.png\">\n  </div>\n\nFirst you need to setup your VPS. To do this you need to run:\n\n```bash\nsidekick init\n```\n\nThen you need to enter the following:\n\n- IP Address of your VPS\n- An email address to use for setting up SSL certs\n\nAfter that Sidekick will setup many things on your VPS - Usually takes around 2 mins.\nIf you run this command once more and enter a different IP Address, Sidekick will warn you that you are overriding the current config with a prompt.\n\nYou can use flags instead. Read more [in the docs](https://www.sidekickdeploy.com/docs/command/init/).\n\n<details>\n  <summary>What does Sidekick do when I run this command?</summary>\n  \n* Login with `root` user\n* Make a new user `sidekick` and grant sudo access\n* Logout from `root` and login with `sidekick`\n* Disable login with `root` user - security best practice\n* Update and upgrade your Ubuntu system\n* Install `sops` and copy over the public key to your sidekick config file\n* Use `age` to make secret and public keys to use later for encrypting env file.\n* Send public key back to host machine to be used later for encryption\n* Install Docker\n* Add user sidekick to docker group\n* Setup Traefik and SSL certs on your VPS\n</details>\n\n<details>\n  <summary>Which SSH key will Sidekick use to login?</summary>\n\nSidekick will look up the default keys in your default .ssh directory in the following order:\n\n- id_rsa.pub\n- id_ecdsa.pub\n- id_ed25519.pub\n\nSidekick will also get all keys from the `ssh-agent` and try them as well. If you want to use a custom key and not a default one, you would need to add the to your agent first by running `ssh-add KEY_FILE`\n\n</details>\n\nRead more details about flags and other options for this command [on the docs](https://www.sidekickdeploy.com/docs/command/init/)\n\n### Launch a new application\n\n  <div align=\"center\" >\n    <img width=\"600px\" src=\"/demo/imgs/launch.png\">\n  </div>\n\nIn your application folder, make sure you have a working `Dockerfile` that you can build and run. Also make sure you know at which port your app is expecting to receive traffic.\n\nThen run:\n\n```bash\nsidekick launch\n```\n\nThen you need to enter the following:\n\n- Url friendly name of your app - if you opt to use `sslip.io` domain for testing this would be your subdomain\n- HTTP exposed port for your app to get requests - Sidekick will scan your docker file to try to extract this number and default it.\n- Domain at which you want this application to be reachable - If you choose your own domain make sure to point the domain to your VPS IP address; otherwise we default to `sslip.io` domain so you can play around.\n- If you have any `env` file with secrets in it. Sidekick will attempt to find `.env` file in the root of your folder. Sidekick will use `sops` to encrypt your env file and inject the values securely at run time.\n\nShould take around 2 more mins to be able to visit your application live on the web if all goes well.\n\n<details>\n  <summary>What does Sidekick do when I run this command</summary>\n  \n* Build your docker image locally for linux\n* Move the docker image to your VPS directly\n* Encrypt your env file, if available and push it to your VPS\n* Use sops to decrypt your env file and start and env with the values injected\n* Spin up your docker image using docker compose and route traffic to it using Traefik on the specified port\n</details>\n\n### Deploy a new version\n\n  <div align=\"center\" >\n    <img width=\"600px\" src=\"/demo/imgs/deploy.png\">\n  </div>\nWith your application deployed, it's super simple to deploy a new version.\n\nAt any point any time you need to only run:\n\n```bash\nsidekick deploy\n```\n\nThat's all. It won't take long, we use cache from earlier docker images, your latest version should be up soon.\nSidekick will deploy the new version without any downtime - you can see more in the source code.\nThis command will also do a couple of things behind the scenes. You can check that below\n\n<details>\n  <summary>What does Sidekick do when I run this command</summary>\n  \n* Build your docker image locally for linux\n* Compare your latest env file checksum for changes from last time you deployed your application.\n* If your env file has changed, sidekick will re-encrypt it and replace the encrypted.env file on your server.\n* Deploy the new version with zero downtime deploys so you don't miss any traffic. \n</details>\n\n### Deploy a preview environment/app\n\n  <div align=\"center\" >\n    <img width=\"600px\" src=\"/demo/imgs/preview.png\">\n  </div>\nSidekick also allows you to deploy preview apps at any point from your application. Preview apps are attached to your commit hash and require a clean git tree before you can initiate them. \nOnce you have a clean git tree, you can run the following command to deploy a preview app:\n\n```bash\nsidekick deploy preview\n```\n\n<details>\n  <summary>What does Sidekick do when I run this command</summary>\n  \n* Build your docker image locally for linux\n* Tag the new image with the short checksum of your git commit\n* Encrypt your env file, if available and push it to your VPS\n* Add a new folder inside your app folder called \"preview\" where Sidekick will store and manage all your preview deployments\n* Deploy a new version of your app reachable on a short hash based subdomain\n</details>\n\n## Inspiration\n\n- https://fly.io/\n- https://kamal-deploy.org/\n\n## Vision\n\nSimple CLI tool that can help you:\n\n- Setup your VPS\n- Deploy all your side projects on a single VPS\n- Load balance multiple container per project\n- Deploy new versions with Zero downtime\n- Deploy preview environments with ease\n- Manage env secrets in a secure way\n- Connect any number of domains and subdomains to your projects with ease\n\n## Remove sidekick\n\nYou can easily remove sidekick if you hate it.\n\n```bash\nbrew uninstall sidekick\n```\n\n---\n\n## Roadmap\n\nI still have a couple more feature I want to add here. Also considering some of those to be on a paid version.\n\n- ✅ Preview env deployments\n- A way to deploy more complicated projects defined in docker compose file\n- Better zero downtime deploys with watchtower\n- Firewall setup\n- Managing multiple VPSs\n- Easy way to deploy databases with one command\n- TUI for monitoring your VPS\n- Streaming down compose logs - ala `fly logs`\n- Auto deploy on image push - to work with CICD better\n- Git hooks setup for managing migrations and other concerns\n"
  },
  {
    "path": "cmd/config/config.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\npackage config\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/pterm/pterm\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nvar ConfigCmd = &cobra.Command{\n\tUse:   \"config\",\n\tShort: \"Subcommands for modifying sidekick config\",\n}\n\nvar currentContextCmd = &cobra.Command{\n\tUse:   \"current\",\n\tShort: \"Get the current context from sidekick config\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Println(err)\n\t\t}\n\t\tfmt.Println(config.CurrentContext)\n\t},\n}\n\nvar useContextCmd = &cobra.Command{\n\tUse:   \"use [context-name]\",\n\tShort: \"Switch the current context in sidekick config\",\n\tArgs:  cobra.ExactArgs(1),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Println(err)\n\t\t}\n\n\t\tcontextName := args[0]\n\t\tconfig.CurrentContext = contextName\n\t\tconfig.Save(viper.GetString(\"config\"))\n\t},\n}\n\nvar migrateCmd = &cobra.Command{\n\tUse:   \"migrate\",\n\tShort: \"Migrate the old sidekick config to the new config\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tvar serverConfig utils.SidekickServer\n\t\tcontent, err := os.ReadFile(viper.GetString(\"config\"))\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Println(err)\n\t\t}\n\t\terr = yaml.Unmarshal(content, &serverConfig)\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Println(err)\n\t\t}\n\n\t\tserverConfig.Name = \"default\"\n\t\tdefaultContext := utils.SidekickContext{\n\t\t\tName:   \"default\",\n\t\t\tServer: \"default\",\n\t\t}\n\t\tnewConfig := utils.SidekickConfig{\n\t\t\tVersion:        \"1\",\n\t\t\tServers:        []utils.SidekickServer{serverConfig},\n\t\t\tContexts:       []utils.SidekickContext{defaultContext},\n\t\t\tCurrentContext: defaultContext.Name,\n\t\t}\n\t\terr = newConfig.Print()\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Println(err)\n\t\t}\n\t},\n}\n\nfunc init() {\n\tConfigCmd.AddCommand(currentContextCmd)\n\tConfigCmd.AddCommand(useContextCmd)\n\tConfigCmd.AddCommand(migrateCmd)\n}\n"
  },
  {
    "path": "cmd/deploy/deploy.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage deploy\n\nimport (\n\t\"crypto/md5\"\n\t\"fmt\"\n\t\"net\"\n\t\"os\"\n\t\"os/exec\"\n\t\"slices\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/charmbracelet/log\"\n\tteaLog \"github.com/charmbracelet/log\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/pterm/pterm\"\n\t\"github.com/spf13/cobra\"\n\t\"golang.org/x/crypto/ssh\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nfunc prelude(config *utils.SidekickConfig) (utils.SidekickAppConfig, utils.SidekickServer) {\n\tif !utils.FileExists(\"./sidekick.yml\") {\n\t\tpterm.Error.Println(`Sidekick config not found in current directory Run sidekick launch`)\n\t\tos.Exit(1)\n\t}\n\n\tappConfig, loadError := utils.LoadAppConfig()\n\tif loadError != nil {\n\t\tpanic(loadError)\n\t}\n\n\t// Older version of app config does not have server name\n\t// We will try to match the first server with IP matching the url\n\tif appConfig.Server == \"\" {\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Info(\"An older version of sidekick.yml is found. Attempting to match a server from url...\")\n\t\tips, err := net.LookupIP(appConfig.Url)\n\t\tif err != nil {\n\t\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Fatal(err)\n\t\t}\n\t\tfor _, server := range config.Servers {\n\t\t\tif slices.ContainsFunc(ips, func(ip net.IP) bool {\n\t\t\t\treturn ip.String() == server.Address\n\t\t\t}) {\n\t\t\t\tappConfig.Server = server.Name\n\t\t\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Info(\"Found server\", \"name\", server.Name, \"IP\", server.Address)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tif appConfig.Server == \"\" {\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Fatal(\"Unable to find a server that this app was deployed.\")\n\t}\n\n\tserver, err := config.FindServer(appConfig.Server)\n\tif err != nil {\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Sidekick Config\"}).Fatal(err)\n\t}\n\n\tif server.SecretKey == \"\" {\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Error(\"Recent changes to how Sidekick handles secrets prevents you from launcing a new application.\")\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Info(\"To fix this, run `Sidekick init` with the same server address you have now.\")\n\t\trender.GetLogger(teaLog.Options{Prefix: \"Backward Compat\"}).Info(\"Learn more at www.sidekickdeploy.com/docs/design/encryption\")\n\t\tos.Exit(1)\n\t}\n\n\treturn appConfig, server\n}\n\nfunc stage1Login(server *utils.SidekickServer) (*ssh.Client, error) {\n\tsshClient, err := utils.Login(server.Address, \"sidekick\")\n\treturn sshClient, err\n}\n\nfunc stage2EnvFile(appConfig utils.SidekickAppConfig, p *tea.Program, server *utils.SidekickServer) (bool, string, error) {\n\tdefer os.Remove(\"encrypted.env\")\n\tenvFileChanged := false\n\tcurrentEnvFileHash := \"\"\n\tif appConfig.Env.File != \"\" {\n\t\tenvFileContent, envFileErr := os.ReadFile(fmt.Sprintf(\"./%s\", appConfig.Env.File))\n\t\tif envFileErr != nil {\n\t\t\treturn false, \"\", fmt.Errorf(\"failed to read environment file: %w\", envFileErr)\n\t\t}\n\t\tcurrentEnvFileHash = fmt.Sprintf(\"%x\", md5.Sum(envFileContent))\n\t\tenvFileChanged = appConfig.Env.Hash != currentEnvFileHash\n\t\tif envFileChanged {\n\t\t\t// encrypt new env file\n\t\t\tenvCmd := exec.Command(\"sh\", \"-s\", \"-\", server.PublicKey, fmt.Sprintf(\"./%s\", appConfig.Env.File))\n\t\t\tenvCmd.Stdin = strings.NewReader(utils.EnvEncryptionScript)\n\t\t\tenvCmdErrPipe, _ := envCmd.StderrPipe()\n\t\t\tgo render.SendLogsToTUI(envCmdErrPipe, p)\n\t\t\tif envCmdErr := envCmd.Run(); envCmdErr != nil {\n\t\t\t\treturn false, \"\", fmt.Errorf(\"failed to encrypt environment file: %w\", envCmdErr)\n\t\t\t}\n\t\t\tencryptSyncCmd := exec.Command(\"rsync\", \"-v\", \"encrypted.env\", fmt.Sprintf(\"%s@%s:%s\", \"sidekick\", server.Address, fmt.Sprintf(\"./%s\", appConfig.Name)))\n\t\t\tencryptSyncCmdErrPipe, _ := encryptSyncCmd.StderrPipe()\n\t\t\tgo render.SendLogsToTUI(encryptSyncCmdErrPipe, p)\n\t\t\tif encryptSyncCmdErr := encryptSyncCmd.Run(); encryptSyncCmdErr != nil {\n\t\t\t\treturn false, \"\", fmt.Errorf(\"failed to sync encrypted environment file to server: %w\", encryptSyncCmdErr)\n\t\t\t}\n\t\t}\n\t}\n\treturn envFileChanged, currentEnvFileHash, nil\n}\n\nfunc stage3BuildDockerImage(appConfig utils.SidekickAppConfig, p *tea.Program, server *utils.SidekickServer) error {\n\tcwd, _ := os.Getwd()\n\tdockerPlatformId := server.PlatformId\n\tdockerBuildCmd := exec.Command(\"docker\", \"build\", \"--tag\", appConfig.Name, \"--progress=plain\", fmt.Sprintf(\"--platform=%s\", dockerPlatformId), cwd)\n\tdockerBuildCmdErrPipe, _ := dockerBuildCmd.StderrPipe()\n\tgo render.SendLogsToTUI(dockerBuildCmdErrPipe, p)\n\n\tif dockerBuildErr := dockerBuildCmd.Run(); dockerBuildErr != nil {\n\t\treturn fmt.Errorf(\"failed to build Docker image: %w\", dockerBuildErr)\n\t}\n\treturn nil\n}\n\nfunc stage4SaveDockerImage(appConfig utils.SidekickAppConfig, p *tea.Program) error {\n\timgFileName := fmt.Sprintf(\"%s-latest.tar\", appConfig.Name)\n\timgSaveCmd := exec.Command(\"docker\", \"save\", \"-o\", imgFileName, appConfig.Name)\n\timgSaveCmdErrPipe, _ := imgSaveCmd.StderrPipe()\n\tgo render.SendLogsToTUI(imgSaveCmdErrPipe, p)\n\n\tif imgSaveCmdErr := imgSaveCmd.Run(); imgSaveCmdErr != nil {\n\t\treturn fmt.Errorf(\"failed to save Docker image: %w\", imgSaveCmdErr)\n\t}\n\treturn nil\n}\n\nfunc stage5MoveDockerImage(appConfig utils.SidekickAppConfig, p *tea.Program, server *utils.SidekickServer) error {\n\timgFileName := fmt.Sprintf(\"%s-latest.tar\", appConfig.Name)\n\tremoteDist := fmt.Sprintf(\"%s@%s:./%s\", \"sidekick\", server.Address, appConfig.Name)\n\timgMoveCmd := exec.Command(\"scp\", \"-C\", imgFileName, remoteDist)\n\timgMoveCmdErrorPipe, _ := imgMoveCmd.StderrPipe()\n\tgo render.SendLogsToTUI(imgMoveCmdErrorPipe, p)\n\n\tif imgMovCmdErr := imgMoveCmd.Run(); imgMovCmdErr != nil {\n\t\treturn fmt.Errorf(\"failed to move Docker image to server: %w\", imgMovCmdErr)\n\t}\n\tos.Remove(imgFileName)\n\treturn nil\n}\n\nfunc stage6Deploy(sshClient *ssh.Client, appConfig utils.SidekickAppConfig, envFileChanged bool, currentEnvFileHash string, p *tea.Program, server *utils.SidekickServer) error {\n\tdockerLoadOutChan, _, sessionErr := utils.RunCommand(sshClient, fmt.Sprintf(\"cd %s && docker load -i %s-latest.tar\", appConfig.Name, appConfig.Name))\n\tif sessionErr != nil {\n\t\treturn fmt.Errorf(\"failed to load docker image on server: %w\", sessionErr)\n\t}\n\n\tgo func() {\n\t\tp.Send(render.LogMsg{LogLine: <-dockerLoadOutChan + \"\\n\"})\n\t\ttime.Sleep(time.Millisecond * 100)\n\t}()\n\n\treplacer := strings.NewReplacer(\n\t\t\"$service_name\", appConfig.Name,\n\t\t\"$app_port\", fmt.Sprint(appConfig.Port),\n\t\t\"$has_env\", appConfig.Env.File,\n\t)\n\n\tdeployScript := replacer.Replace(utils.DeployAppScript)\n\tutils.RunCommandWithTUIHook(sshClient, deployScript, p, utils.EnvVar{\"SOPS_AGE_KEY\": server.SecretKey})\n\ttime.Sleep(time.Second * 2)\n\n\tcleanOutChan, _, sessionErr := utils.RunCommand(sshClient, fmt.Sprintf(\"cd %s && rm %s\", appConfig.Name, fmt.Sprintf(\"%s-latest.tar\", appConfig.Name)))\n\tif sessionErr != nil {\n\t\treturn fmt.Errorf(\"failed to clean up image file on server: %w\", sessionErr)\n\t}\n\tgo func() {\n\t\tp.Send(render.LogMsg{LogLine: <-cleanOutChan + \"\\n\"})\n\t\ttime.Sleep(time.Millisecond * 100)\n\t}()\n\n\tlatestVersion := strings.Split(appConfig.Version, \"\")[1]\n\tlatestVersionInt, _ := strconv.ParseInt(latestVersion, 0, 64)\n\tappConfig.Version = fmt.Sprintf(\"V%d\", latestVersionInt+1)\n\t// env file changed ? -> update hash\n\tif envFileChanged {\n\t\tappConfig.Env.Hash = currentEnvFileHash\n\t}\n\tymlData, _ := yaml.Marshal(&appConfig)\n\tos.WriteFile(\"./sidekick.yml\", ymlData, 0644)\n\n\treturn nil\n}\n\nvar DeployCmd = &cobra.Command{\n\tUse:   \"deploy\",\n\tShort: \"Deploy a new version of your application to your VPS using Sidekick\",\n\tLong: `This command deploys a new version of your application to your VPS.\nIt assumes that your VPS is already configured and that your application is ready for deployment`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tstart := time.Now()\n\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t}\n\t\tappConfig, sidekickServer := prelude(config)\n\n\t\tcmdStages := []render.Stage{\n\t\t\trender.MakeStage(\"Validating connection with VPS\", \"VPS is reachable\", false),\n\t\t\trender.MakeStage(\"Updating secrets if needed\", \"Env file check complete\", false),\n\t\t\trender.MakeStage(\"Building latest docker image of your app\", \"Latest docker image built\", true),\n\t\t\trender.MakeStage(\"Saving docker image locally\", \"Image saved successfully\", false),\n\t\t\trender.MakeStage(\"Moving image to your server\", \"Image moved and loaded successfully\", false),\n\t\t\trender.MakeStage(\"Deploying a new version of your application\", \"Deployed new version successfully\", true),\n\t\t}\n\t\tp := tea.NewProgram(render.TuiModel{\n\t\t\tStages:      cmdStages,\n\t\t\tBannerMsg:   fmt.Sprintf(\"Deploying a new env of your app to server %s (%s) 😎\", sidekickServer.Name, sidekickServer.Address),\n\t\t\tActiveIndex: 0,\n\t\t\tQuitting:    false,\n\t\t\tAllDone:     false,\n\t\t})\n\n\t\tgo func() {\n\t\t\tsshClient, err := stage1Login(&sidekickServer)\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: \"Failed to connect to VPS: \" + err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tenvFileChanged, currentEnvFileHash, err := stage2EnvFile(appConfig, p, &sidekickServer)\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage3BuildDockerImage(appConfig, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage4SaveDockerImage(appConfig, p); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 200)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage5MoveDockerImage(appConfig, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 200)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage6Deploy(sshClient, appConfig, envFileChanged, currentEnvFileHash, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: err.Error()})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 500)\n\t\t\tp.Send(render.AllDoneMsg{Message: \"🚀 Deployed successfully in \" + time.Since(start).Round(time.Second).String() + \".\\n\" + \"😎 View your app at https://\" + appConfig.Url})\n\t\t}()\n\n\t\tif _, err := p.Run(); err != nil {\n\t\t\tfmt.Println(\"Error running program:\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t},\n}\n"
  },
  {
    "path": "cmd/destroy.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage cmd\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/spf13/cobra\"\n)\n\n// destroyCmd represents the destroy command\nvar destroyCmd = &cobra.Command{\n\tUse:   \"destroy\",\n\tShort: \"A command to destroy your app on the VPS and remove the container and the images\",\n\tLong:  `This command is destructive and will remove everything related to your application from the VPS. Please use it with care`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tfmt.Println(\"destroy called\")\n\t},\n}\n\nfunc init() {\n\trootCmd.AddCommand(destroyCmd)\n\n\t// Here you will define your flags and configuration settings.\n\n\t// Cobra supports Persistent Flags which will work for this command\n\t// and all subcommands, e.g.:\n\t// destroyCmd.PersistentFlags().String(\"foo\", \"\", \"A help for foo\")\n\n\t// Cobra supports local flags which will only run when this command\n\t// is called directly, e.g.:\n\t// destroyCmd.Flags().BoolP(\"toggle\", \"t\", false, \"Help message for toggle\")\n}\n"
  },
  {
    "path": "cmd/initialize/initialize.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage initialize\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"time\"\n\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/docker/docker/pkg/namesgenerator\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"golang.org/x/crypto/ssh\"\n)\n\nfunc stage1LocalReqs() error {\n\tif _, err := exec.LookPath(\"sops\"); err != nil {\n\t\tcmd := exec.Command(\"brew\", \"install\", \"sops\")\n\t\tif err := cmd.Run(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to install sops: %w\", err)\n\t\t}\n\t}\n\tif _, err := exec.LookPath(\"age\"); err != nil {\n\t\tcmd := exec.Command(\"brew\", \"install\", \"age\")\n\t\tif err := cmd.Run(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to install age: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc stage2Login(server string) (*ssh.Client, string, error) {\n\tusers := []string{\"root\", \"sidekick\"}\n\tfor _, user := range users {\n\t\tclient, err := utils.Login(server, user)\n\t\tif err == nil {\n\t\t\treturn client, user, nil\n\t\t}\n\t}\n\treturn nil, \"\", fmt.Errorf(\"unable to establish SSH connection\")\n}\n\nfunc stage3UserSetup(client *ssh.Client, loggedInUser string) error {\n\thasSidekickUser := true\n\toutChan, _, err := utils.RunCommand(client, \"id -u sidekick\")\n\tif err != nil {\n\t\thasSidekickUser = false\n\t} else {\n\t\toutput := <-outChan\n\t\tif output == \"\" {\n\t\t\thasSidekickUser = false\n\t\t}\n\t}\n\n\tif !hasSidekickUser && loggedInUser == \"root\" {\n\t\tif err := utils.RunStage(client, utils.UsersetupStage); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc stage4VPSSetup(client *ssh.Client, p *tea.Program, server *utils.SidekickServer) error {\n\t// get the linux distro\n\toutChan, _, _ := utils.RunCommand(client, \"grep '^ID=' /etc/os-release | awk -F'=' '{print $2}'\")\n\tlinuxDistro := <-outChan\n\tserver.Distro = linuxDistro\n\n\t// get docker platform id\n\tcmdOutChan, _, _ := utils.RunCommand(client, \"uname -m\")\n\tarch := <-cmdOutChan\n\tif arch == \"x86_64\" {\n\t\tserver.PlatformId = \"linux/amd64\"\n\t}\n\tif arch == \"aarch64\" {\n\t\tserver.PlatformId = \"linux/arm64\"\n\t}\n\n\tif err := utils.RunCommandsWithTUIHook(client, utils.SetupStage.Commands, p); err != nil {\n\t\treturn err\n\t}\n\n\tif server.PublicKey == \"\" || server.SecretKey == \"\" {\n\t\tcmd := exec.Command(\"age-keygen\")\n\t\toutput, err := cmd.Output()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\toutStr := string(output)\n\t\tlines := strings.Split(outStr, \"\\n\")\n\t\tif len(lines) >= 3 {\n\t\t\tserver.SecretKey = lines[2]\n\t\t\tparts := strings.Split(lines[1], \":\")\n\t\t\tif len(parts) > 1 {\n\t\t\t\tserver.PublicKey = strings.ReplaceAll(parts[1], \" \", \"\")\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc stage5Docker(client *ssh.Client, p *tea.Program) error {\n\tdockerReady := false\n\toutChan, _, err := utils.RunCommand(client, `command -v docker &> /dev/null && command -v docker compose &> /dev/null && echo \"1\" || echo \"0\"`)\n\tif err == nil {\n\t\toutput := <-outChan\n\t\tif output == \"1\" {\n\t\t\tdockerReady = true\n\t\t}\n\t}\n\n\tif !dockerReady {\n\t\tif err := utils.RunCommandsWithTUIHook(client, utils.DockerStage.Commands, p); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc stage6Traefik(client *ssh.Client, email string, p *tea.Program) error {\n\ttraefikSetup := false\n\toutChan, _, err := utils.RunCommand(client, `[ -d \"traefik\" ] && echo \"1\" || echo \"0\"`)\n\tif err == nil {\n\t\toutput := <-outChan\n\t\tif output == \"1\" {\n\t\t\ttraefikSetup = true\n\t\t}\n\t}\n\n\tif !traefikSetup {\n\t\ttraefikStage := utils.GetTraefikStage(email)\n\t\tif err := utils.RunCommandsWithTUIHook(client, traefikStage.Commands, p); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nvar InitCmd = &cobra.Command{\n\tUse:   \"init\",\n\tShort: \"Init sidekick CLI and configure your VPS to host your apps\",\n\tLong: `This command will run you through the setup steps to get sidekick loaded on your VPS.\n\t\tYou wil need to provide your VPS IPv4 address and a registry to host your docker images.\n\t\t`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tstart := time.Now()\n\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"%s\", err)\n\t\t}\n\n\t\tskipPromptsFlag, _ := cmd.Flags().GetBool(\"yes\")\n\t\tserver, _ := cmd.Flags().GetString(\"server\")\n\t\tcertEmail, _ := cmd.Flags().GetString(\"email\")\n\t\tname, _ := cmd.Flags().GetString(\"name\")\n\n\t\tif name == \"\" {\n\t\t\trandomName := namesgenerator.GetRandomName(0)\n\t\t\tname = render.GenerateTextQuestion(\"Please enter a name for your VPS\", randomName, \"\")\n\t\t}\n\n\t\tif server == \"\" {\n\t\t\tserver = render.GenerateTextQuestion(\"Please enter the IPv4 Address of your VPS\", \"\", \"\")\n\t\t\tif !utils.IsValidIPAddress(server) {\n\t\t\t\tlog.Fatalf(\"You entered an incorrect IP Address - %s\", server)\n\t\t\t}\n\t\t}\n\n\t\tif certEmail == \"\" {\n\t\t\tcertEmail = render.GenerateTextQuestion(\"Please enter an email for use with TLS certs\", \"\", \"\")\n\t\t\tif certEmail == \"\" {\n\t\t\t\tlog.Fatalf(\"An email is needed before you proceed\")\n\t\t\t}\n\t\t}\n\n\t\tsidekickServer, err := config.FindServer(name)\n\t\tif err != nil {\n\t\t\tsidekickServer = utils.SidekickServer{\n\t\t\t\tName:      name,\n\t\t\t\tAddress:   server,\n\t\t\t\tCertEmail: certEmail,\n\t\t\t}\n\t\t}\n\n\t\tif sidekickServer.Name == name && sidekickServer.Address != server && sidekickServer.PublicKey != \"\" && !skipPromptsFlag {\n\t\t\tconfirm := render.GenerateTextQuestion(fmt.Sprintf(\"The server '%s' was previously setup with Sidekick using a different address. Would you like to overwrite the settings? (y/n)\", sidekickServer.Name), \"n\", \"\")\n\t\t\tif strings.ToLower(confirm) != \"y\" {\n\t\t\t\tfmt.Println(\"\\nYou can use a different server name to complete the setup\")\n\t\t\t\tos.Exit(0)\n\t\t\t}\n\t\t}\n\n\t\tsidekickServer.Address = server\n\t\tsidekickServer.CertEmail = certEmail\n\n\t\tcmdStages := []render.Stage{\n\t\t\trender.MakeStage(\"Setting up your local env\", \"Installed local requirements successfully\", false),\n\t\t\trender.MakeStage(\"Logging in to VPS\", \"Logged in successfully\", false),\n\t\t\trender.MakeStage(\"Adding user Sidekick\", \"User Sidekick added successfully\", false),\n\t\t\trender.MakeStage(\"Setting up VPS\", \"VPS setup successfully\", true),\n\t\t\trender.MakeStage(\"Setting up Docker\", \"Docker setup successfully\", true),\n\t\t\trender.MakeStage(\"Setting up Traefik\", \"Traefik setup successfully\", true),\n\t\t}\n\n\t\tp := tea.NewProgram(render.TuiModel{\n\t\t\tStages:      cmdStages,\n\t\t\tBannerMsg:   \"Sidekick booting up! 🚀\",\n\t\t\tActiveIndex: 0,\n\t\t\tQuitting:    false,\n\t\t\tAllDone:     false,\n\t\t})\n\n\t\tutils.Login(server, \"root\")\n\n\t\tgo func() {\n\t\t\tif err := stage1LocalReqs(); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Local requirements check failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tsshClient, loggedInUser, err := stage2Login(server)\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Login failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage3UserSetup(sshClient, loggedInUser); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"User setup failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tsidekickClient, err := utils.Login(server, \"sidekick\")\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Failed to login as sidekick: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage4VPSSetup(sidekickClient, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"VPS setup failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage5Docker(sidekickClient, p); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Docker setup failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err := stage6Traefik(sidekickClient, certEmail, p); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Traefik setup failed: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconfig.AddOrReplaceServer(sidekickServer)\n\t\t\tnewContext := utils.SidekickContext{Name: sidekickServer.Name, Server: sidekickServer.Name}\n\t\t\tconfig.AddOrReplaceContext(newContext)\n\t\t\tconfig.CurrentContext = newContext.Name\n\n\t\t\tif err := config.Save(viper.GetString(\"config\")); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Failed to write config: %s\", err)})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tp.Send(render.AllDoneMsg{Message: \"VPS Setup Done in \" + time.Since(start).Round(time.Second).String() + \",\" + \"\\n\" + \"Your VPS is ready! You can now run Sidekick launch in your app folder\"})\n\t\t}()\n\n\t\tif _, err := p.Run(); err != nil {\n\t\t\tfmt.Println(\"Error running program:\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t},\n}\n\nfunc init() {\n\tInitCmd.Flags().StringP(\"server\", \"s\", \"\", \"Set the IP address of your Server\")\n\tInitCmd.Flags().StringP(\"email\", \"e\", \"\", \"An email address to be used for SSL certs\")\n\tInitCmd.Flags().StringP(\"name\", \"n\", \"\", \"Set the name of your Server\")\n\tInitCmd.Flags().BoolP(\"yes\", \"y\", false, \"Skip all validation prompts\")\n}\n"
  },
  {
    "path": "cmd/launch/launch.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage launch\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/charmbracelet/huh\"\n\t\"github.com/charmbracelet/log\"\n\t\"github.com/docker/docker/api/types/build\"\n\t\"github.com/docker/docker/client\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/spf13/cobra\"\n\t\"golang.org/x/crypto/ssh\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nvar dockerClient *client.Client\n\nfunc getDockerClient() (*client.Client, error) {\n\tif dockerClient != nil {\n\t\treturn dockerClient, nil\n\t}\n\n\tcli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdockerClient = cli\n\n\treturn cli, nil\n}\n\nfunc prelude(server *utils.SidekickServer) string {\n\tif server.SecretKey == \"\" {\n\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Error(\"Recent changes to how Sidekick handles secrets prevents you from launcing a new application.\")\n\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Info(\"To fix this, run `Sidekick init` with the same server address you have now.\")\n\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Info(\"Learn more at www.sidekickdeploy.com/docs/design/encryption\")\n\t\tos.Exit(1)\n\t}\n\n\tif utils.FileExists(\"./sidekick.yml\") {\n\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Setup\"}).Error(\"Sidekick config exists in this project.\")\n\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Setup\"}).Info(\"You can deploy a new version of your application with Sidekick deploy.\")\n\t\tos.Exit(1)\n\t}\n\n\tif utils.FileExists(\"./Dockerfile\") {\n\t\trender.GetLogger(log.Options{Prefix: \"Dockerfile\"}).Info(\"Detected - scanning file for details\")\n\t} else {\n\t\trender.GetLogger(log.Options{Prefix: \"Dockerfile\"}).Fatal(\"No dockerfile found in current directory.\")\n\t}\n\n\tres, err := os.ReadFile(\"./Dockerfile\")\n\tif err != nil {\n\t\trender.GetLogger(log.Options{Prefix: \"Dockerfile\"}).Fatal(\"Unable to process your dockerfile\")\n\t}\n\n\tappPort := \"\"\n\tfor _, line := range strings.Split(string(res), \"\\n\") {\n\t\tif strings.HasPrefix(line, \"EXPOSE \") {\n\t\t\tappPort = strings.TrimPrefix(line, \"EXPOSE \")\n\t\t}\n\t}\n\treturn appPort\n}\n\nfunc stage1(server *utils.SidekickServer) (*ssh.Client, error) {\n\tsshClient, err := utils.Login(server.Address, \"sidekick\")\n\treturn sshClient, err\n}\n\nfunc stage2(appName string, p *tea.Program, server *utils.SidekickServer) error {\n\tcwd, _ := os.Getwd()\n\tcwdTar, err := utils.TarDirectoryToReader(cwd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdockerClient, err := getDockerClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx := context.Background()\n\tresp, err := dockerClient.ImageBuild(ctx, cwdTar, build.ImageBuildOptions{\n\t\tTags:     []string{fmt.Sprintf(\"%s:latest\", appName)},\n\t\tPlatform: server.PlatformId,\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n\trender.SendDockerBuildLogsToTUI(resp.Body, p)\n\ttime.Sleep(time.Millisecond * 100)\n\treturn nil\n}\n\nfunc stage3(appName string, p *tea.Program) error {\n\tctx := context.Background()\n\timageReader, err := dockerClient.ImageSave(ctx, []string{fmt.Sprintf(\"%s:latest\", appName)})\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer imageReader.Close()\n\n\timgFileName := fmt.Sprintf(\"%s-latest.tar\", appName)\n\toutFile, err := os.Create(imgFileName)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\tif _, err := io.Copy(outFile, imageReader); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc stage4(sshClient *ssh.Client, appName string, p *tea.Program, server *utils.SidekickServer) error {\n\t_, _, sessionErr := utils.RunCommand(sshClient, fmt.Sprintf(\"mkdir %s\", appName))\n\tif sessionErr != nil {\n\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr.Error()})\n\t}\n\timgFileName := fmt.Sprintf(\"%s-latest.tar\", appName)\n\tremoteDist := fmt.Sprintf(\"%s@%s:./%s\", \"sidekick\", server.Address, appName)\n\timgMoveCmd := exec.Command(\"scp\", \"-C\", imgFileName, remoteDist)\n\timgMoveCmdErrorPipe, _ := imgMoveCmd.StderrPipe()\n\tgo render.SendLogsToTUI(imgMoveCmdErrorPipe, p)\n\n\tif imgMovCmdErr := imgMoveCmd.Run(); imgMovCmdErr != nil {\n\t\treturn imgMovCmdErr\n\t}\n\tdefer os.Remove(imgFileName)\n\tdockerLoadOutChan, _, sessionErr := utils.RunCommand(sshClient, fmt.Sprintf(\"cd %s && docker load -i %s && rm %s\", appName, imgFileName, imgFileName))\n\tgo func() {\n\t\tp.Send(render.LogMsg{LogLine: <-dockerLoadOutChan + \"\\n\"})\n\t\ttime.Sleep(time.Millisecond * 50)\n\t}()\n\tif sessionErr != nil {\n\t\ttime.Sleep(time.Millisecond * 100)\n\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr.Error()})\n\t}\n\treturn nil\n}\n\nfunc stage5(sshClient *ssh.Client, appName string, appPort string, appDomain string, hasEnvFile bool, envFileName string, envFileChecksum string, p *tea.Program, server *utils.SidekickServer) error {\n\trsyncCmd := exec.Command(\"rsync\", \"docker-compose.yaml\", fmt.Sprintf(\"%s@%s:%s\", \"sidekick\", server.Address, fmt.Sprintf(\"./%s\", appName)))\n\trsyncCmErr := rsyncCmd.Run()\n\tif rsyncCmErr != nil {\n\t\treturn rsyncCmErr\n\t}\n\n\tif hasEnvFile {\n\t\tencryptSync := exec.Command(\"rsync\", \"encrypted.env\", fmt.Sprintf(\"%s@%s:%s\", \"sidekick\", server.Address, fmt.Sprintf(\"./%s\", appName)))\n\t\tencryptSyncErr := encryptSync.Run()\n\t\tif encryptSyncErr != nil {\n\t\t\treturn encryptSyncErr\n\t\t}\n\n\t\trunAppCmdOutChan, _, sessionErr1 := utils.RunCommand(sshClient, fmt.Sprintf(`cd %s && export SOPS_AGE_KEY=%s && sops exec-env encrypted.env 'docker compose -p sidekick up -d'`, appName, server.SecretKey))\n\t\tgo func() {\n\t\t\tp.Send(render.LogMsg{LogLine: <-runAppCmdOutChan + \"\\n\"})\n\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t}()\n\t\tif sessionErr1 != nil {\n\t\t\treturn sessionErr1\n\t\t}\n\t} else {\n\t\trunAppCmdOutChan, _, sessionErr1 := utils.RunCommand(sshClient, fmt.Sprintf(`cd %s && docker compose -p sidekick up -d`, appName))\n\t\tgo func() {\n\t\t\tp.Send(render.LogMsg{LogLine: <-runAppCmdOutChan + \"\\n\"})\n\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t}()\n\t\tif sessionErr1 != nil {\n\t\t\treturn sessionErr1\n\t\t}\n\t}\n\n\tportNumber, err := strconv.ParseUint(appPort, 0, 64)\n\tif err != nil {\n\t\treturn err\n\t}\n\tenvConfig := utils.SidekickAppEnvConfig{}\n\tif hasEnvFile {\n\t\tenvConfig.File = envFileName\n\t\tenvConfig.Hash = envFileChecksum\n\t}\n\t// save app config in same folder\n\tsidekickAppConfig := utils.SidekickAppConfig{\n\t\tName:      appName,\n\t\tVersion:   \"V1\",\n\t\tPort:      portNumber,\n\t\tUrl:       appDomain,\n\t\tCreatedAt: time.Now().Format(time.UnixDate),\n\t\tEnv:       envConfig,\n\t\tServer:    server.Name,\n\t}\n\tymlData, _ := yaml.Marshal(&sidekickAppConfig)\n\tos.WriteFile(\"./sidekick.yml\", ymlData, 0644)\n\treturn nil\n}\n\nvar LaunchCmd = &cobra.Command{\n\tUse:   \"launch\",\n\tShort: \"Launch a new application to host on your VPS with Sidekick\",\n\tLong:  `This command will run you through the basic setup to add a new application to your VPS.`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tstart := time.Now()\n\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t}\n\t\tvar selectedCtx utils.SidekickContext\n\t\toptions := make([]huh.Option[utils.SidekickContext], 0, len(config.Contexts))\n\t\tfor _, c := range config.Contexts {\n\t\t\tserver, err := config.FindServer(c.Server)\n\t\t\tif err != nil {\n\t\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t\t}\n\t\t\toptions = append(options, huh.NewOption(fmt.Sprintf(\"%s (%s)\", server.Name, server.Address), c))\n\t\t}\n\t\tform := huh.NewForm(\n\t\t\thuh.NewGroup(\n\t\t\t\thuh.NewSelect[utils.SidekickContext]().\n\t\t\t\t\tTitle(\"Select a VPS\").\n\t\t\t\t\tOptions(options...).\n\t\t\t\t\tValue(&selectedCtx),\n\t\t\t),\n\t\t)\n\t\terr = form.Run()\n\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Context Selection\"}).Fatalf(\"%s\", err)\n\t\t}\n\n\t\tsidekickServer, err := config.FindServerByContext(selectedCtx.Name)\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t}\n\n\t\tappPort := prelude(&sidekickServer)\n\n\t\tappName := render.GenerateTextQuestion(\"Please enter your app url friendly app name\", \"\", \"will identify your app containers\")\n\t\tappPort = render.GenerateTextQuestion(\"Please enter the port at which the app receives request\", appPort, \"\")\n\t\tappDomain := render.GenerateTextQuestion(\"Please enter the domain to point the app to\", fmt.Sprintf(\"%s.%s.sslip.io\", appName, sidekickServer.Address), \"must point to your VPS address\")\n\t\tenvFileName := render.GenerateTextQuestion(\"Please enter which env file you would like to load\", \".env\", \"\")\n\n\t\thasEnvFile := false\n\t\tdockerEnvProperty := []string{}\n\t\tenvFileChecksum := \"\"\n\t\tif utils.FileExists(fmt.Sprintf(\"./%s\", envFileName)) {\n\t\t\thasEnvFile = true\n\t\t\trender.GetLogger(log.Options{Prefix: \"Env File\"}).Infof(\"Detected - Loading env vars from %s\", envFileName)\n\t\t\tenvHandleErr := utils.HandleEnvFile(envFileName, &dockerEnvProperty, &envFileChecksum, sidekickServer.PublicKey)\n\t\t\tif envHandleErr != nil {\n\t\t\t\trender.GetLogger(log.Options{Prefix: \"Env File\"}).Fatalf(\"Something went wrong %s\", envHandleErr)\n\t\t\t}\n\t\t\tdefer os.Remove(\"encrypted.env\")\n\t\t} else {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Env File\"}).Info(\"Not Detected - Skipping env parsing\")\n\t\t}\n\n\t\t// make a docker service\n\t\timageName := appName\n\t\tnewService := utils.DockerService{\n\t\t\tImage:   imageName,\n\t\t\tRestart: \"unless-stopped\",\n\t\t\tLabels: []string{\n\t\t\t\t\"traefik.enable=true\",\n\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.rule=Host(`%s`)\", appName, appDomain),\n\t\t\t\tfmt.Sprintf(\"traefik.http.services.%s.loadbalancer.server.port=%s\", appName, appPort),\n\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.tls=true\", appName),\n\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.tls.certresolver=default\", appName),\n\t\t\t\t\"traefik.docker.network=sidekick\",\n\t\t\t},\n\t\t\tEnvironment: dockerEnvProperty,\n\t\t\tNetworks: []string{\n\t\t\t\t\"sidekick\",\n\t\t\t},\n\t\t}\n\t\tnewDockerCompose := utils.DockerComposeFile{\n\t\t\tServices: map[string]utils.DockerService{\n\t\t\t\tappName: newService,\n\t\t\t},\n\t\t\tNetworks: map[string]utils.DockerNetwork{\n\t\t\t\t\"sidekick\": {\n\t\t\t\t\tExternal: true,\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t\tdockerComposeFile, err := yaml.Marshal(&newDockerCompose)\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"Error marshalling YAML: %v\\n\", err)\n\t\t\treturn\n\t\t}\n\t\terr = os.WriteFile(\"docker-compose.yaml\", dockerComposeFile, 0644)\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"Error writing file: %v\\n\", err)\n\t\t\treturn\n\t\t}\n\t\tdefer os.Remove(\"docker-compose.yaml\")\n\n\t\tcmdStages := []render.Stage{\n\t\t\trender.MakeStage(\"Validating connection with VPS\", \"VPS is reachable\", false),\n\t\t\trender.MakeStage(\"Building latest docker image of your app\", \"Latest docker image built\", true),\n\t\t\trender.MakeStage(\"Saving docker image locally\", \"Image saved successfully\", false),\n\t\t\trender.MakeStage(\"Moving image to your server\", \"Image moved and loaded successfully\", false),\n\t\t\trender.MakeStage(\"Setting up your application\", \"Application setup successfully\", false),\n\t\t}\n\t\tp := tea.NewProgram(render.TuiModel{\n\t\t\tStages:      cmdStages,\n\t\t\tBannerMsg:   \"Launching your application on your VPS 🚀\",\n\t\t\tActiveIndex: 0,\n\t\t\tQuitting:    false,\n\t\t\tAllDone:     false,\n\t\t})\n\n\t\tgo func() {\n\t\t\tsshClient, err := stage1(&sidekickServer)\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: \"Something went wrong logging in to your VPS\"})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err = stage2(appName, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Something went wrong building your docker image: %s\", err)})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err = stage3(appName, p); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Something went wrong saving docker image to a file: %s\", err)})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err = stage4(sshClient, appName, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Something went wrong moving the image to your VPS: %s\", err)})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tif err = stage5(sshClient, appName, appPort, appDomain, hasEnvFile, envFileName, envFileChecksum, p, &sidekickServer); err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Something went wrong booting up your app: %s\", err)})\n\t\t\t}\n\n\t\t\tp.Send(render.AllDoneMsg{Message: \"🚀 Deployed successfully in \" + time.Since(start).Round(time.Second).String() + \".\\n\" + \"😎 View your app at https://\" + appDomain})\n\t\t}()\n\n\t\tif _, err := p.Run(); err != nil {\n\t\t\tfmt.Println(\"Error running program:\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t},\n}\n"
  },
  {
    "path": "cmd/preview/list/list.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage previewList\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/charmbracelet/huh\"\n\t\"github.com/charmbracelet/lipgloss\"\n\t\"github.com/charmbracelet/lipgloss/table\"\n\t\"github.com/charmbracelet/log\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/spf13/cobra\"\n)\n\n// listCmd represents the list command\nvar ListCmd = &cobra.Command{\n\tUse:     \"list\",\n\tAliases: []string{\"ls\"},\n\tShort:   \"This command lists all the preview environments\",\n\tLong:    `This command lists all the preview environments that are currently running on your VPS.`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tappConfig, appConfigErr := utils.LoadAppConfig()\n\t\tif appConfigErr != nil {\n\t\t\tlog.Fatalf(\"Unable to load your config file. Might be corrupted\")\n\t\t}\n\t\tif len(appConfig.PreviewEnvs) == 0 {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Preview Envs\"}).Info(\"Not Found in current project\")\n\t\t\tos.Exit(0)\n\t\t}\n\t\theader := lipgloss.NewStyle().Foreground(lipgloss.Color(\"77\")).MarginTop(1).MarginLeft(1).Render(\"Currently running preview envs:\")\n\t\ttableString := table.New().\n\t\t\tBorder(lipgloss.RoundedBorder()).\n\t\t\tBorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(\"99\"))).\n\t\t\tStyleFunc(func(row, col int) lipgloss.Style {\n\t\t\t\tswitch {\n\t\t\t\tcase row == 0:\n\t\t\t\t\treturn lipgloss.NewStyle().Foreground(lipgloss.Color(\"60\")).Align(lipgloss.Center)\n\t\t\t\tdefault:\n\t\t\t\t\treturn lipgloss.NewStyle().Foreground(lipgloss.Color(\"78\")).PaddingLeft(1).PaddingRight(1)\n\t\t\t\t}\n\t\t\t}).\n\t\t\tHeaders(\"Commit\", \"Image\", \"Deployed At\", \"URL\")\n\n\t\thashSlice := []huh.Option[string]{}\n\t\tfor v := range appConfig.PreviewEnvs {\n\t\t\thashSlice = append(hashSlice, huh.NewOption(v, v))\n\t\t\ttableString.Row(v, appConfig.PreviewEnvs[v].Image, appConfig.PreviewEnvs[v].CreatedAt, appConfig.PreviewEnvs[v].Url)\n\t\t}\n\t\tfmt.Println(header)\n\t\tfmt.Println(tableString)\n\t},\n}\n"
  },
  {
    "path": "cmd/preview/preview.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage preview\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"time\"\n\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/charmbracelet/log\"\n\tpreviewList \"github.com/mightymoud/sidekick/cmd/preview/list\"\n\tpreviewRemove \"github.com/mightymoud/sidekick/cmd/preview/remove\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nvar PreviewCmd = &cobra.Command{\n\tUse:   \"preview\",\n\tShort: \"Deploy a preview environment for your application\",\n\tLong:  `Sidekick allows you to deploy preview environment based on commit hash`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tstart := time.Now()\n\n\t\tconfig, err := utils.GetSidekickConfigFromCmdContext(cmd)\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t}\n\t\tsidekickServer, err := config.FindServerByContext(config.CurrentContext)\n\t\tif err != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatalf(\"%s\", err)\n\t\t}\n\n\t\tappConfig, appConfigErr := utils.LoadAppConfig()\n\t\tif appConfigErr != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Setup\"}).Error(\"Sidekick config exits in this project.\")\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Setup\"}).Info(\"You can deploy a new version of your application with Sidekick deploy.\")\n\t\t\tos.Exit(1)\n\t\t}\n\n\t\tif sidekickServer.SecretKey == \"\" {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Error(\"Recent changes to how Sidekick handles secrets prevents you from launcing a new application.\")\n\t\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Info(\"To fix this, run `Sidekick init` with the same server address you have now.\")\n\t\t\trender.GetLogger(log.Options{Prefix: \"Backward Compat\"}).Info(\"Learn more at www.sidekickdeploy.com/docs/design/encryption\")\n\t\t\tos.Exit(1)\n\t\t}\n\n\t\tgitTreeCheck := exec.Command(\"sh\", \"-s\", \"-\")\n\t\tgitTreeCheck.Stdin = strings.NewReader(utils.CheckGitTreeScript)\n\t\toutput, _ := gitTreeCheck.Output()\n\t\tif string(output) != \"all good\\n\" {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Preview Cmd\"}).Error(\"Please commit any changes to git before deploying a preview environment\")\n\t\t\tos.Exit(1)\n\t\t}\n\n\t\tgitShortHashCmd := exec.Command(\"sh\", \"-s\", \"-\")\n\t\tgitShortHashCmd.Stdin = strings.NewReader(\"git rev-parse --short HEAD\")\n\t\thashOutput, hashErr := gitShortHashCmd.Output()\n\t\tif hashErr != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Preview Cmd\"}).Error(\"Issue occurred getting git commit hash: %s\", hashErr)\n\t\t\tos.Exit(1)\n\t\t}\n\t\tdeployHash := strings.TrimSuffix(string(hashOutput), \"\\n\")\n\n\t\tcmdStages := []render.Stage{\n\t\t\trender.MakeStage(\"Validating connection with VPS\", \"VPS is reachable\", false),\n\t\t\trender.MakeStage(\"Building latest docker image of your app\", \"Latest docker image built\", true),\n\t\t\trender.MakeStage(\"Saving docker image locally\", \"Image saved successfully\", false),\n\t\t\trender.MakeStage(\"Moving image to your server\", \"Image moved and loaded successfully\", false),\n\t\t\trender.MakeStage(\"Deploying a preview env of your application\", \"Preview env setup successfully\", false),\n\t\t}\n\t\tp := tea.NewProgram(render.TuiModel{\n\t\t\tStages:      cmdStages,\n\t\t\tBannerMsg:   \"Deploying a preview env of your app 😎\",\n\t\t\tActiveIndex: 0,\n\t\t\tQuitting:    false,\n\t\t\tAllDone:     false,\n\t\t})\n\n\t\tgo func() {\n\t\t\tsshClient, err := utils.Login(viper.GetString(\"serverAddress\"), \"sidekick\")\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{})\n\t\t\t}\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tdockerEnvProperty := []string{}\n\t\t\tenvFileChecksum := \"\"\n\t\t\tif appConfig.Env.File != \"\" {\n\t\t\t\tenvErr := utils.HandleEnvFile(appConfig.Env.File, &dockerEnvProperty, &envFileChecksum, sidekickServer.PublicKey)\n\t\t\t\tif envErr != nil {\n\t\t\t\t\tpanic(envErr)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\timageName := fmt.Sprintf(\"%s:%s\", appConfig.Name, deployHash)\n\t\t\tserviceName := fmt.Sprintf(\"%s-%s\", appConfig.Name, deployHash)\n\t\t\tpreviewURL := fmt.Sprintf(\"%s.%s\", deployHash, appConfig.Url)\n\t\t\tnewService := utils.DockerService{\n\t\t\t\tImage: imageName,\n\t\t\t\tLabels: []string{\n\t\t\t\t\t\"traefik.enable=true\",\n\t\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.rule=Host(`%s`)\", serviceName, previewURL),\n\t\t\t\t\tfmt.Sprintf(\"traefik.http.services.%s.loadbalancer.server.port=%s\", serviceName, fmt.Sprint(appConfig.Port)),\n\t\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.tls=true\", serviceName),\n\t\t\t\t\tfmt.Sprintf(\"traefik.http.routers.%s.tls.certresolver=default\", serviceName),\n\t\t\t\t\t\"traefik.docker.network=sidekick\",\n\t\t\t\t},\n\t\t\t\tEnvironment: dockerEnvProperty,\n\t\t\t\tNetworks: []string{\n\t\t\t\t\t\"sidekick\",\n\t\t\t\t},\n\t\t\t}\n\t\t\tnewDockerCompose := utils.DockerComposeFile{\n\t\t\t\tServices: map[string]utils.DockerService{\n\t\t\t\t\tserviceName: newService,\n\t\t\t\t},\n\t\t\t\tNetworks: map[string]utils.DockerNetwork{\n\t\t\t\t\t\"sidekick\": {\n\t\t\t\t\t\tExternal: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t\tdockerComposeFile, err := yaml.Marshal(&newDockerCompose)\n\t\t\tif err != nil {\n\t\t\t\tfmt.Printf(\"Error marshalling YAML: %v\\n\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\terr = os.WriteFile(\"docker-compose.yaml\", dockerComposeFile, 0644)\n\t\t\tif err != nil {\n\t\t\t\tfmt.Printf(\"Error writing file: %v\\n\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcwd, _ := os.Getwd()\n\t\t\tdockerImage := fmt.Sprintf(\"%s:%s\", appConfig.Name, deployHash)\n\t\t\tdockerBuildCmd := exec.Command(\"docker\", \"build\", \"--tag\", dockerImage, \"--progress=plain\", \"--platform=linux/amd64\", cwd)\n\t\t\tdockerBuildCmdErrPipe, _ := dockerBuildCmd.StderrPipe()\n\t\t\tgo render.SendLogsToTUI(dockerBuildCmdErrPipe, p)\n\n\t\t\tif dockerBuildErr := dockerBuildCmd.Run(); dockerBuildErr != nil {\n\t\t\t\tp.Send(render.ErrorMsg{})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\timgFileName := fmt.Sprintf(\"%s-%s.tar\", appConfig.Name, deployHash)\n\t\t\timgSaveCmd := exec.Command(\"docker\", \"save\", \"-o\", imgFileName, dockerImage)\n\t\t\timgSaveCmdErrPipe, _ := imgSaveCmd.StderrPipe()\n\t\t\tgo render.SendLogsToTUI(imgSaveCmdErrPipe, p)\n\n\t\t\tif imgSaveCmdErr := imgSaveCmd.Run(); imgSaveCmdErr != nil {\n\t\t\t\tp.Send(render.ErrorMsg{})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\t_, _, sessionErr0 := utils.RunCommand(sshClient, fmt.Sprintf(`mkdir -p %s/preview/%s`, appConfig.Name, deployHash))\n\t\t\tif sessionErr0 != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr0.Error()})\n\t\t\t}\n\n\t\t\tremoteDist := fmt.Sprintf(\"%s@%s:./%s\", \"sidekick\", viper.GetString(\"serverAddress\"), appConfig.Name)\n\t\t\timgMoveCmd := exec.Command(\"scp\", \"-C\", imgFileName, remoteDist)\n\t\t\timgMoveCmdErrorPipe, _ := imgMoveCmd.StderrPipe()\n\t\t\tgo render.SendLogsToTUI(imgMoveCmdErrorPipe, p)\n\n\t\t\tif imgMovCmdErr := imgMoveCmd.Run(); imgMovCmdErr != nil {\n\t\t\t\tp.Send(render.ErrorMsg{})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 200)\n\n\t\t\tdockerLoadOutChan, _, sessionErr := utils.RunCommand(sshClient, fmt.Sprintf(\"cd %s && docker load -i %s && rm %s\", appConfig.Name, imgFileName, imgFileName))\n\t\t\tgo func() {\n\t\t\t\tp.Send(render.LogMsg{LogLine: <-dockerLoadOutChan + \"\\n\"})\n\t\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t\t}()\n\t\t\tif sessionErr != nil {\n\t\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr.Error()})\n\t\t\t}\n\n\t\t\ttime.Sleep(time.Millisecond * 100)\n\t\t\tp.Send(render.NextStageMsg{})\n\n\t\t\tpreviewFolder := fmt.Sprintf(\"./%s/preview/%s\", appConfig.Name, deployHash)\n\t\t\trsyncCmd := exec.Command(\"rsync\", \"docker-compose.yaml\", fmt.Sprintf(\"%s@%s:%s\", \"sidekick\", viper.GetString(\"serverAddress\"), previewFolder))\n\t\t\trsyncCmErr := rsyncCmd.Run()\n\t\t\tif rsyncCmErr != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: rsyncCmErr.Error()})\n\t\t\t}\n\n\t\t\tif appConfig.Env.File != \"\" {\n\t\t\t\tencryptSync := exec.Command(\"rsync\", \"encrypted.env\", fmt.Sprintf(\"%s@%s:%s\", \"sidekick\", viper.GetString(\"serverAddress\"), previewFolder))\n\t\t\t\tencryptSyncErrr := encryptSync.Run()\n\t\t\t\tif encryptSyncErrr != nil {\n\t\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: encryptSyncErrr.Error()})\n\t\t\t\t}\n\n\t\t\t\trunAppCmdOutChan, _, sessionErr1 := utils.RunCommand(sshClient, fmt.Sprintf(`cd %s && export SOPS_AGE_KEY=%s && sops exec-env encrypted.env 'docker compose -p sidekick up -d'`, previewFolder, viper.GetString(\"secretKey\")))\n\t\t\t\tgo func() {\n\t\t\t\t\tp.Send(render.LogMsg{LogLine: <-runAppCmdOutChan + \"\\n\"})\n\t\t\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t\t\t}()\n\t\t\t\tif sessionErr1 != nil {\n\t\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr1.Error()})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\trunAppCmdOutChan, _, sessionErr1 := utils.RunCommand(sshClient, fmt.Sprintf(`cd %s && docker compose -p sidekick up -d`, previewFolder))\n\t\t\t\tgo func() {\n\t\t\t\t\tp.Send(render.LogMsg{LogLine: <-runAppCmdOutChan + \"\\n\"})\n\t\t\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t\t\t}()\n\t\t\t\tif sessionErr1 != nil {\n\t\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: sessionErr1.Error()})\n\t\t\t\t}\n\t\t\t}\n\t\t\tpreviewEnvConfig := utils.SidekickPreview{\n\t\t\t\tUrl:       fmt.Sprintf(\"https://%s\", previewURL),\n\t\t\t\tImage:     imageName,\n\t\t\t\tCreatedAt: time.Now().Format(time.UnixDate),\n\t\t\t}\n\t\t\tif len(appConfig.PreviewEnvs) == 0 {\n\t\t\t\tappConfig.PreviewEnvs = map[string]utils.SidekickPreview{}\n\t\t\t}\n\t\t\tappConfig.PreviewEnvs[deployHash] = previewEnvConfig\n\n\t\t\tymlData, _ := yaml.Marshal(&appConfig)\n\t\t\tos.WriteFile(\"./sidekick.yml\", ymlData, 0644)\n\n\t\t\tos.Remove(\"docker-compose.yaml\")\n\t\t\tos.Remove(\"encrypted.env\")\n\t\t\tos.Remove(imgFileName)\n\n\t\t\tp.Send(render.AllDoneMsg{Message: \"🚀 Deployed successfully in \" + time.Since(start).Round(time.Second).String() + \".\\n\" + \"😎 View your app at https://\" + previewURL})\n\n\t\t}()\n\n\t\tif _, err := p.Run(); err != nil {\n\t\t\tfmt.Println(\"Error running program:\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t},\n}\n\nfunc init() {\n\tPreviewCmd.AddCommand(previewList.ListCmd)\n\tPreviewCmd.AddCommand(previewRemove.RemoveCmd)\n}\n"
  },
  {
    "path": "cmd/preview/remove/remove.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage previewRemove\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/charmbracelet/huh\"\n\t\"github.com/charmbracelet/huh/spinner\"\n\t\"github.com/charmbracelet/lipgloss\"\n\t\"github.com/charmbracelet/lipgloss/table\"\n\t\"github.com/charmbracelet/log\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nvar RemoveCmd = &cobra.Command{\n\tUse:     \"remove\",\n\tAliases: []string{\"rm\"},\n\tShort:   \"This command removes a preview environment\",\n\tLong:    \"This command removes a preview environment by the git hash associated with them\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tif configErr := utils.ViperInit(); configErr != nil {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Sidekick Config\"}).Fatal(\"Not found - Run Sidekick init first\")\n\t\t}\n\t\tif !utils.FileExists(\"./sidekick.yml\") {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Project Config\"}).Fatal(\"Not found in current directory Run sidekick launch\")\n\t\t}\n\n\t\tappConfig, appConfigErr := utils.LoadAppConfig()\n\t\tif appConfigErr != nil {\n\t\t\tlog.Fatalf(\"Unable to load your config file. Might be corrupted\")\n\t\t}\n\n\t\tvar selected string\n\t\tvar confirm bool\n\n\t\tif len(appConfig.PreviewEnvs) == 0 {\n\t\t\trender.GetLogger(log.Options{Prefix: \"Preview Envs\"}).Info(\"Not Found in current project\")\n\t\t\tos.Exit(0)\n\t\t}\n\n\t\theader := lipgloss.NewStyle().Foreground(lipgloss.Color(\"77\")).MarginTop(1).MarginLeft(1).Render(\"Currently running preview envs:\")\n\t\ttableString := table.New().\n\t\t\tBorder(lipgloss.RoundedBorder()).\n\t\t\tBorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(\"99\"))).\n\t\t\tStyleFunc(func(row, col int) lipgloss.Style {\n\t\t\t\tswitch {\n\t\t\t\tcase row == 0:\n\t\t\t\t\treturn lipgloss.NewStyle().Foreground(lipgloss.Color(\"60\")).Align(lipgloss.Center)\n\t\t\t\tdefault:\n\t\t\t\t\treturn lipgloss.NewStyle().Foreground(lipgloss.Color(\"78\")).PaddingLeft(1).PaddingRight(1)\n\t\t\t\t}\n\t\t\t}).\n\t\t\tHeaders(\"Commit\", \"Image\", \"Deployed At\", \"URL\")\n\n\t\thashSlice := []huh.Option[string]{}\n\t\tfor v := range appConfig.PreviewEnvs {\n\t\t\thashSlice = append(hashSlice, huh.NewOption(v, v))\n\t\t\ttableString.Row(v, appConfig.PreviewEnvs[v].Image, appConfig.PreviewEnvs[v].CreatedAt, appConfig.PreviewEnvs[v].Url)\n\t\t}\n\t\tfmt.Println(header)\n\t\tfmt.Println(tableString)\n\t\thuh.NewSelect[string]().\n\t\t\tTitle(\"Which preview env would you like to delete?\").\n\t\t\tOptions(hashSlice...).\n\t\t\tValue(&selected).\n\t\t\tRun()\n\t\thuh.NewConfirm().\n\t\t\tTitle(\"Are you sure?\").\n\t\t\tAffirmative(\"Yes!\").\n\t\t\tNegative(\"No.\").\n\t\t\tValue(&confirm).\n\t\t\tRun()\n\t\tif !confirm {\n\t\t\tos.Exit(0)\n\t\t} else {\n\t\t\taction := func() {\n\t\t\t\tdeletePreviewEnv(selected)\n\t\t\t}\n\t\t\tspinner.New().\n\t\t\t\tTitle(\"Deleting your selected preview environment...\").\n\t\t\t\tAction(action).\n\t\t\t\tRun()\n\n\t\t\tfmt.Println(\"Preview env deleted successfully!\")\n\t\t}\n\n\t},\n}\n\nfunc deletePreviewEnv(hash string) {\n\n\tappConfig, appConfigErr := utils.LoadAppConfig()\n\tif appConfigErr != nil {\n\t\tlog.Fatalf(\"Unable to load your config file. Might be corrupted\")\n\t}\n\tsshClient, err := utils.Login(viper.GetString(\"serverAddress\"), \"sidekick\")\n\tif err != nil {\n\t\tlog.Fatal(\"Unable to login to your VPS\")\n\t}\n\n\t_, _, dockerDwnErr := utils.RunCommand(sshClient, fmt.Sprintf(\"cd %s/preview/%s && docker rm -f sidekick-%s-%s-1 && docker image rm %s:%s\", appConfig.Name, hash, appConfig.Name, hash, appConfig.Name, hash))\n\tif dockerDwnErr != nil {\n\t\tlog.Fatalf(\"Issue happened stopping your service: %s\", dockerDwnErr)\n\t}\n\t_, _, folderRmErr := utils.RunCommand(sshClient, fmt.Sprintf(\"rm -rf %s/preview/%s\", appConfig.Name, hash))\n\tif folderRmErr != nil {\n\t\tlog.Fatalf(\"Issue happened deleting the preview folder: %s\", folderRmErr)\n\t}\n\n\tdelete(appConfig.PreviewEnvs, hash)\n\tymlData, _ := yaml.Marshal(&appConfig)\n\tos.WriteFile(\"./sidekick.yml\", ymlData, 0644)\n}\n"
  },
  {
    "path": "cmd/root.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage cmd\n\nimport (\n\t\"context\"\n\t\"os\"\n\t\"path/filepath\"\n\n\t\"github.com/mightymoud/sidekick/cmd/config\"\n\t\"github.com/mightymoud/sidekick/cmd/deploy\"\n\t\"github.com/mightymoud/sidekick/cmd/initialize\"\n\t\"github.com/mightymoud/sidekick/cmd/launch\"\n\t\"github.com/mightymoud/sidekick/cmd/preview\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/pterm/pterm\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nvar version = \"dev\"\n\nvar rootCmd = &cobra.Command{\n\tUse:     \"sidekick\",\n\tVersion: version,\n\tShort:   \"CLI to self-host all your apps on a single VPS without vendor locking\",\n\tLong:    `With sidekick you can deploy any number of applications to a single VPS, connect multiple domains and much more.`,\n\tPersistentPreRun: func(cmd *cobra.Command, args []string) {\n\t\tinitConfig(cmd)\n\t},\n}\n\nfunc Execute() {\n\terr := rootCmd.Execute()\n\tif err != nil {\n\t\tos.Exit(1)\n\t}\n}\n\nfunc init() {\n\trootCmd.SetVersionTemplate(`{{println .Version}}`)\n\n\thome, err := os.UserHomeDir()\n\tif err != nil {\n\t\tpterm.Error.Println(err)\n\t\tos.Exit(1)\n\t}\n\tdefaultConfigPath := filepath.Join(home, \".config\", \"sidekick\", \"default.yaml\")\n\n\trootCmd.PersistentFlags().String(\"config\", defaultConfigPath, \"Path to sidekick config file\")\n\n\trootCmd.AddCommand(initialize.InitCmd)\n\trootCmd.AddCommand(preview.PreviewCmd)\n\trootCmd.AddCommand(deploy.DeployCmd)\n\trootCmd.AddCommand(launch.LaunchCmd)\n\trootCmd.AddCommand(config.ConfigCmd)\n}\n\nfunc initConfig(cmd *cobra.Command) {\n\tvar config utils.SidekickConfig\n\n\tviper.BindEnv(\"config\", \"SIDEKICK_CONFIG\")\n\tviper.BindPFlag(\"config\", cmd.Flags().Lookup(\"config\"))\n\n\tconfigPath := viper.GetString(\"config\")\n\tcontent, err := os.ReadFile(configPath)\n\n\tif err != nil {\n\t\tif requireConfigFile(cmd) {\n\t\t\tpterm.Fatal.Println(\"Sidekick config not found - Run sidekick init\")\n\t\t}\n\t\tconfig = utils.SidekickConfig{\n\t\t\tVersion:        \"1\",\n\t\t\tCurrentContext: \"\",\n\t\t\tContexts:       []utils.SidekickContext{},\n\t\t\tServers:        []utils.SidekickServer{},\n\t\t}\n\t} else {\n\t\terr := yaml.Unmarshal(content, &config)\n\t\tif err != nil {\n\t\t\tpterm.Fatal.Sprintf(\"Error unmarshaling the config yaml file: %s\", err)\n\t\t}\n\t}\n\n\tif config.Version != \"1\" && !shouldSkipConfigVersionCheck(cmd) {\n\t\tpterm.Fatal.Println(\"An older version of the config file found. Please run 'sidekick config migrate'.\")\n\t}\n\n\tctx := context.WithValue(cmd.Context(), \"config\", &config)\n\tcmd.SetContext(ctx)\n}\n\nfunc requireConfigFile(cmd *cobra.Command) bool {\n\tcmdName := cmd.Name()\n\n\tif cmdName == \"init\" || cmdName == \"help\" {\n\t\treturn false\n\t}\n\n\tif parentCmd := cmd.Parent(); parentCmd != nil {\n\t\tif parentCmd.Name() == \"config\" && cmdName == \"migrate\" {\n\t\t\treturn false\n\t\t}\n\t}\n\n\treturn true\n}\n\nfunc shouldSkipConfigVersionCheck(cmd *cobra.Command) bool {\n\tcmdName := cmd.Name()\n\n\tif cmdName == \"help\" {\n\t\treturn true\n\t}\n\n\tif parentCmd := cmd.Parent(); parentCmd != nil {\n\t\tif parentCmd.Name() == \"config\" && cmdName == \"migrate\" {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/mightymoud/sidekick\n\ngo 1.24.0\n\ntoolchain go1.24.5\n\nrequire (\n\tgithub.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7\n\tgithub.com/charmbracelet/bubbletea v1.3.6\n\tgithub.com/charmbracelet/lipgloss v1.1.0\n\tgithub.com/charmbracelet/log v0.4.0\n\tgithub.com/docker/docker v28.5.1+incompatible\n\tgithub.com/joho/godotenv v1.5.1\n\tgithub.com/skeema/knownhosts v1.3.0\n\tgithub.com/spf13/cobra v1.8.1\n\tgithub.com/spf13/viper v1.19.0\n\tgolang.org/x/crypto v0.45.0\n\tgopkg.in/yaml.v3 v3.0.1\n)\n\nrequire (\n\tatomicgo.dev/cursor v0.2.0 // indirect\n\tatomicgo.dev/keyboard v0.2.9 // indirect\n\tatomicgo.dev/schedule v0.1.0 // indirect\n\tgithub.com/Microsoft/go-winio v0.6.2 // indirect\n\tgithub.com/atotto/clipboard v0.1.4 // indirect\n\tgithub.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect\n\tgithub.com/catppuccin/go v0.3.0 // indirect\n\tgithub.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect\n\tgithub.com/charmbracelet/x/ansi v0.9.3 // indirect\n\tgithub.com/charmbracelet/x/cellbuf v0.0.13 // indirect\n\tgithub.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect\n\tgithub.com/charmbracelet/x/term v0.2.1 // indirect\n\tgithub.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect\n\tgithub.com/containerd/errdefs v1.0.0 // indirect\n\tgithub.com/containerd/errdefs/pkg v0.3.0 // indirect\n\tgithub.com/containerd/log v0.1.0 // indirect\n\tgithub.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect\n\tgithub.com/distribution/reference v0.6.0 // indirect\n\tgithub.com/docker/go-connections v0.6.0 // indirect\n\tgithub.com/docker/go-units v0.5.0 // indirect\n\tgithub.com/dustin/go-humanize v1.0.1 // indirect\n\tgithub.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect\n\tgithub.com/felixge/httpsnoop v1.0.4 // indirect\n\tgithub.com/fsnotify/fsnotify v1.7.0 // indirect\n\tgithub.com/go-logfmt/logfmt v0.6.0 // indirect\n\tgithub.com/go-logr/logr v1.4.3 // indirect\n\tgithub.com/go-logr/stdr v1.2.2 // indirect\n\tgithub.com/gookit/color v1.5.4 // indirect\n\tgithub.com/hashicorp/hcl v1.0.0 // indirect\n\tgithub.com/lithammer/fuzzysearch v1.1.8 // indirect\n\tgithub.com/lucasb-eyer/go-colorful v1.2.0 // indirect\n\tgithub.com/magiconair/properties v1.8.7 // indirect\n\tgithub.com/mattn/go-isatty v0.0.20 // indirect\n\tgithub.com/mattn/go-localereader v0.0.1 // indirect\n\tgithub.com/mattn/go-runewidth v0.0.16 // indirect\n\tgithub.com/mitchellh/hashstructure/v2 v2.0.2 // indirect\n\tgithub.com/mitchellh/mapstructure v1.5.0 // indirect\n\tgithub.com/moby/docker-image-spec v1.3.1 // indirect\n\tgithub.com/moby/moby v28.5.2+incompatible // indirect\n\tgithub.com/moby/sys/atomicwriter v0.1.0 // indirect\n\tgithub.com/moby/term v0.5.2 // indirect\n\tgithub.com/morikuni/aec v1.0.0 // indirect\n\tgithub.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect\n\tgithub.com/muesli/cancelreader v0.2.2 // indirect\n\tgithub.com/muesli/reflow v0.3.0 // indirect\n\tgithub.com/muesli/termenv v0.16.0 // indirect\n\tgithub.com/opencontainers/go-digest v1.0.0 // indirect\n\tgithub.com/opencontainers/image-spec v1.1.1 // indirect\n\tgithub.com/pelletier/go-toml/v2 v2.2.2 // indirect\n\tgithub.com/pkg/errors v0.9.1 // indirect\n\tgithub.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect\n\tgithub.com/rivo/uniseg v0.4.7 // indirect\n\tgithub.com/sagikazarmark/locafero v0.4.0 // indirect\n\tgithub.com/sagikazarmark/slog-shim v0.1.0 // indirect\n\tgithub.com/sahilm/fuzzy v0.1.1 // indirect\n\tgithub.com/sourcegraph/conc v0.3.0 // indirect\n\tgithub.com/spf13/afero v1.11.0 // indirect\n\tgithub.com/spf13/cast v1.6.0 // indirect\n\tgithub.com/subosito/gotenv v1.6.0 // indirect\n\tgithub.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect\n\tgo.opentelemetry.io/auto/sdk v1.1.0 // indirect\n\tgo.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect\n\tgo.opentelemetry.io/otel v1.38.0 // indirect\n\tgo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect\n\tgo.opentelemetry.io/otel/metric v1.38.0 // indirect\n\tgo.opentelemetry.io/otel/sdk v1.38.0 // indirect\n\tgo.opentelemetry.io/otel/trace v1.38.0 // indirect\n\tgo.uber.org/atomic v1.9.0 // indirect\n\tgo.uber.org/multierr v1.9.0 // indirect\n\tgolang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect\n\tgolang.org/x/sync v0.18.0 // indirect\n\tgolang.org/x/term v0.37.0 // indirect\n\tgolang.org/x/text v0.31.0 // indirect\n\tgopkg.in/ini.v1 v1.67.0 // indirect\n\tgotest.tools/v3 v3.5.2 // indirect\n)\n\nrequire (\n\tgithub.com/charmbracelet/huh v0.8.0\n\tgithub.com/charmbracelet/huh/spinner v0.0.0-20241011224433-983a50776b31\n\tgithub.com/erikgeiser/promptkit v0.9.0\n\tgithub.com/inconshreveable/mousetrap v1.1.0 // indirect\n\tgithub.com/pterm/pterm v0.12.79\n\tgithub.com/spf13/pflag v1.0.5 // indirect\n\tgithub.com/stretchr/testify v1.11.1\n\tgolang.org/x/sys v0.38.0 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "atomicgo.dev/assert v0.0.2 h1:FiKeMiZSgRrZsPo9qn/7vmr7mCsh5SZyXY4YGYiYwrg=\natomicgo.dev/assert v0.0.2/go.mod h1:ut4NcI3QDdJtlmAxQULOmA13Gz6e2DWbSAS8RUOmNYQ=\natomicgo.dev/cursor v0.2.0 h1:H6XN5alUJ52FZZUkI7AlJbUc1aW38GWZalpYRPpoPOw=\natomicgo.dev/cursor v0.2.0/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU=\natomicgo.dev/keyboard v0.2.9 h1:tOsIid3nlPLZ3lwgG8KZMp/SFmr7P0ssEN5JUsm78K8=\natomicgo.dev/keyboard v0.2.9/go.mod h1:BC4w9g00XkxH/f1HXhW2sXmJFOCWbKn9xrOunSFtExQ=\natomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs=\natomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU=\ngithub.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=\ngithub.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=\ngithub.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=\ngithub.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=\ngithub.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=\ngithub.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=\ngithub.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=\ngithub.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=\ngithub.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=\ngithub.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c=\ngithub.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE=\ngithub.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4=\ngithub.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY=\ngithub.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=\ngithub.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=\ngithub.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=\ngithub.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=\ngithub.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=\ngithub.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=\ngithub.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=\ngithub.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=\ngithub.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=\ngithub.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=\ngithub.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=\ngithub.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=\ngithub.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=\ngithub.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=\ngithub.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=\ngithub.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=\ngithub.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=\ngithub.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=\ngithub.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=\ngithub.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=\ngithub.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7 h1:JFgG/xnwFfbezlUnFMJy0nusZvytYysV4SCS2cYbvws=\ngithub.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7/go.mod h1:ISC1gtLcVilLOf23wvTfoQuYbW2q0JevFxPfUzZ9Ybw=\ngithub.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY=\ngithub.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=\ngithub.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI=\ngithub.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo=\ngithub.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=\ngithub.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=\ngithub.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=\ngithub.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=\ngithub.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=\ngithub.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=\ngithub.com/charmbracelet/huh v0.8.0 h1:Xz/Pm2h64cXQZn/Jvele4J3r7DDiqFCNIVteYukxDvY=\ngithub.com/charmbracelet/huh v0.8.0/go.mod h1:5YVc+SlZ1IhQALxRPpkGwwEKftN/+OlJlnJYlDRFqN4=\ngithub.com/charmbracelet/huh/spinner v0.0.0-20241011224433-983a50776b31 h1:HqaYBKXy1eQBnN9tCLJJHaQ+3btqonOVh25LZ/Xaxps=\ngithub.com/charmbracelet/huh/spinner v0.0.0-20241011224433-983a50776b31/go.mod h1:Cxhgl8N0sX9A+EQxedzzGZAalaF8fUVL+JP/pSOW8cI=\ngithub.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=\ngithub.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=\ngithub.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=\ngithub.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=\ngithub.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=\ngithub.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=\ngithub.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=\ngithub.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=\ngithub.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=\ngithub.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=\ngithub.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=\ngithub.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=\ngithub.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=\ngithub.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=\ngithub.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=\ngithub.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=\ngithub.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q=\ngithub.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=\ngithub.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=\ngithub.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=\ngithub.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=\ngithub.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=\ngithub.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=\ngithub.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=\ngithub.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=\ngithub.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=\ngithub.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=\ngithub.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=\ngithub.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=\ngithub.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=\ngithub.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=\ngithub.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=\ngithub.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=\ngithub.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=\ngithub.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=\ngithub.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=\ngithub.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=\ngithub.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=\ngithub.com/docker/docker v28.5.1+incompatible h1:Bm8DchhSD2J6PsFzxC35TZo4TLGR2PdW/E69rU45NhM=\ngithub.com/docker/docker v28.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=\ngithub.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=\ngithub.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=\ngithub.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=\ngithub.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=\ngithub.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=\ngithub.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=\ngithub.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=\ngithub.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=\ngithub.com/erikgeiser/promptkit v0.9.0 h1:3qL1mS/ntCrXdb8sTP/ka82CJ9kEQaGuYXNrYJkWYBc=\ngithub.com/erikgeiser/promptkit v0.9.0/go.mod h1:pU9dtogSe3Jlc2AY77EP7R4WFP/vgD4v+iImC83KsCo=\ngithub.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=\ngithub.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=\ngithub.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=\ngithub.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=\ngithub.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=\ngithub.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=\ngithub.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=\ngithub.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=\ngithub.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=\ngithub.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=\ngithub.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=\ngithub.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=\ngithub.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=\ngithub.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=\ngithub.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=\ngithub.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=\ngithub.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=\ngithub.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=\ngithub.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=\ngithub.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=\ngithub.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=\ngithub.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=\ngithub.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=\ngithub.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=\ngithub.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=\ngithub.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=\ngithub.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=\ngithub.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=\ngithub.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=\ngithub.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=\ngithub.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=\ngithub.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=\ngithub.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU=\ngithub.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=\ngithub.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=\ngithub.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=\ngithub.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=\ngithub.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=\ngithub.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=\ngithub.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=\ngithub.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=\ngithub.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=\ngithub.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=\ngithub.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=\ngithub.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=\ngithub.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=\ngithub.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=\ngithub.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=\ngithub.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=\ngithub.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=\ngithub.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=\ngithub.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=\ngithub.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=\ngithub.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=\ngithub.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=\ngithub.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=\ngithub.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=\ngithub.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=\ngithub.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=\ngithub.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=\ngithub.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=\ngithub.com/moby/moby v28.5.2+incompatible h1:hIn6qcenb3JY1E3STwqEbBvJ8bha+u1LpqjX4CBvNCk=\ngithub.com/moby/moby v28.5.2+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=\ngithub.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=\ngithub.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=\ngithub.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=\ngithub.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=\ngithub.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=\ngithub.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=\ngithub.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=\ngithub.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=\ngithub.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=\ngithub.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=\ngithub.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=\ngithub.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=\ngithub.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=\ngithub.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=\ngithub.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg=\ngithub.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=\ngithub.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=\ngithub.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=\ngithub.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=\ngithub.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=\ngithub.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=\ngithub.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=\ngithub.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=\ngithub.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=\ngithub.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=\ngithub.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=\ngithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngithub.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=\ngithub.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngithub.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=\ngithub.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg=\ngithub.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE=\ngithub.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU=\ngithub.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=\ngithub.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8=\ngithub.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s=\ngithub.com/pterm/pterm v0.12.79 h1:lH3yrYMhdpeqX9y5Ep1u7DejyHy7NSQg9qrBjF9dFT4=\ngithub.com/pterm/pterm v0.12.79/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IGaQAAo=\ngithub.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=\ngithub.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=\ngithub.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=\ngithub.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=\ngithub.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=\ngithub.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=\ngithub.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=\ngithub.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=\ngithub.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=\ngithub.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=\ngithub.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=\ngithub.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=\ngithub.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=\ngithub.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=\ngithub.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=\ngithub.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=\ngithub.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=\ngithub.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY=\ngithub.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M=\ngithub.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=\ngithub.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=\ngithub.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=\ngithub.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=\ngithub.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=\ngithub.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=\ngithub.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=\ngithub.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=\ngithub.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=\ngithub.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=\ngithub.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=\ngithub.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=\ngithub.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=\ngithub.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=\ngithub.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=\ngithub.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=\ngithub.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=\ngithub.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=\ngithub.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=\ngithub.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=\ngithub.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=\ngithub.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=\ngithub.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=\ngithub.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=\ngithub.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=\ngithub.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=\ngithub.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=\ngithub.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=\ngithub.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=\ngithub.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=\ngithub.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=\ngithub.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=\ngo.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=\ngo.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=\ngo.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=\ngo.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=\ngo.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=\ngo.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=\ngo.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=\ngo.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU=\ngo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 h1:aTL7F04bJHUlztTsNGJ2l+6he8c+y/b//eR0jjjemT4=\ngo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0/go.mod h1:kldtb7jDTeol0l3ewcmd8SDvx3EmIE7lyvqbasU3QC4=\ngo.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=\ngo.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=\ngo.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=\ngo.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=\ngo.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=\ngo.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=\ngo.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4=\ngo.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE=\ngo.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=\ngo.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=\ngo.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=\ngo.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=\ngolang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=\ngolang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=\ngolang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=\ngolang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=\ngolang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=\ngolang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=\ngolang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=\ngolang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=\ngolang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=\ngolang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=\ngolang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=\ngolang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=\ngolang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=\ngolang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=\ngolang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=\ngolang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=\ngolang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=\ngolang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=\ngolang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=\ngolang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngoogle.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y=\ngoogle.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 h1:BIRfGDEjiHRrk0QKZe3Xv2ieMhtgRGeLcZQ0mIVn4EY=\ngoogle.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5/go.mod h1:j3QtIyytwqGr1JUDtYXwtMXWPKsEa5LtzIFN1Wn5WvE=\ngoogle.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 h1:eaY8u2EuxbRv7c3NiGK0/NedzVsCcV6hDuU5qPX5EGE=\ngoogle.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5/go.mod h1:M4/wBTSeyLxupu3W3tJtOgB14jILAS/XWPSSa3TAlJc=\ngoogle.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=\ngoogle.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=\ngoogle.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=\ngoogle.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=\ngopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=\ngopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=\ngopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=\ngopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=\ngopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=\ngopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\ngopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\ngopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=\ngopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\ngotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=\ngotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=\n"
  },
  {
    "path": "main.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage main\n\nimport \"github.com/mightymoud/sidekick/cmd\"\n\nfunc main() {\n\tcmd.Execute()\n}\n"
  },
  {
    "path": "render/tui.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage render\n\nimport (\n\t\"bufio\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/charmbracelet/bubbles/spinner\"\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/charmbracelet/lipgloss\"\n\t\"github.com/charmbracelet/lipgloss/tree\"\n)\n\nvar (\n\tspinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(\"63\")).MarginRight(1).MarginLeft(1)\n\tsuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(\"#04B575\")).MarginLeft(1)\n\tcancelStyle  = lipgloss.NewStyle().Foreground(lipgloss.Color(\"220\")).Faint(true).MarginLeft(1)\n\terrorStyle   = lipgloss.NewStyle().Foreground(lipgloss.Color(\"#FF0000\")).MarginLeft(1)\n\tpendingStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(\"240\")).MarginLeft(1)\n\tallDoneStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(\"69\")).MarginTop(1).MarginLeft(1).MarginBottom(1)\n\tappStyle     = lipgloss.NewStyle()\n)\n\nfunc (m TuiModel) Init() tea.Cmd {\n\treturn m.Stages[m.ActiveIndex].Spinner.Tick\n}\n\nfunc (m TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {\n\tswitch msg := msg.(type) {\n\n\tcase tea.KeyMsg:\n\t\tm.Quitting = true\n\n\t\treturn m, tea.Quit\n\n\tcase tea.WindowSizeMsg:\n\t\tm.ViewportHeight = msg.Height\n\t\tm.ViewportWidth = msg.Width\n\t\treturn m, nil\n\n\tcase LogMsg:\n\t\tlogStage := m.Stages[m.ActiveIndex]\n\t\tlogStage.Logs = append(logStage.Logs, msg.LogLine)\n\t\tm.Stages[m.ActiveIndex] = logStage\n\n\t\treturn m, nil\n\n\tcase ErrorMsg:\n\t\tlogStage := m.Stages[m.ActiveIndex]\n\t\tlogStage.HasError = true\n\t\tif msg.ErrorStr != \"\" {\n\t\t\tlogStage.Logs = append(logStage.Logs, msg.ErrorStr)\n\t\t}\n\t\tm.Stages[m.ActiveIndex] = logStage\n\n\t\tWriteStageLogs(logStage, m.ActiveIndex)\n\n\t\treturn m, tea.Quit\n\n\tcase NextStageMsg:\n\t\tm.ActiveIndex = m.ActiveIndex + 1\n\n\t\treturn m, m.Stages[m.ActiveIndex].Spinner.Tick\n\n\tcase AllDoneMsg:\n\t\tm.AllDone = true\n\t\tm.FinalMessage = msg.Message\n\n\t\treturn m, tea.Quit\n\n\tcase spinner.TickMsg:\n\t\tvar cmd tea.Cmd\n\t\tm.Stages[m.ActiveIndex].Spinner, cmd = m.Stages[m.ActiveIndex].Spinner.Update(msg)\n\t\treturn m, cmd\n\tdefault:\n\t\treturn m, nil\n\t}\n}\n\nfunc (m TuiModel) View() string {\n\tvar s string\n\tprintSlice := []string{}\n\n\tprintSlice = append(printSlice, getBannerStyle(m).Render(m.BannerMsg))\n\n\tvar logs string\n\tfor _, res := range m.Stages[m.ActiveIndex].Logs {\n\t\tlogs += res\n\t}\n\n\tfor index, stage := range m.Stages {\n\t\tif !m.AllDone {\n\t\t\tif index < m.ActiveIndex {\n\t\t\t\tprintSlice = append(printSlice, successStyle.Render(\"✔ \"+stage.Success))\n\t\t\t} else if index == m.ActiveIndex {\n\t\t\t\tif !stage.HasError {\n\t\t\t\t\tprintSlice = append(printSlice, stage.Spinner.View()+stage.Title)\n\t\t\t\t} else {\n\t\t\t\t\tu := tree.Root(\"⚠ \" + stage.Title).Child(stage.Logs)\n\t\t\t\t\tprintSlice = append(printSlice, errorStyle.Render(u.String()))\n\t\t\t\t\tprintSlice = append(printSlice, allDoneStyle.Render(\"⚠️ Check sidekick.logs.txt for more details\"))\n\t\t\t\t}\n\t\t\t\tif stage.HasLogs && !stage.HasError {\n\t\t\t\t\tvar t string\n\t\t\t\t\tif !stage.HasError {\n\t\t\t\t\t\tl := len(stage.Logs)\n\t\t\t\t\t\tif l < 5 {\n\t\t\t\t\t\t\tt = getLogContainerStyle(m).Render(stage.Logs...)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tt = getLogContainerStyle(m).Render(stage.Logs[l-5:]...)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tt = getLogContainerStyle(m).Render(stage.Logs...)\n\t\t\t\t\t}\n\t\t\t\t\tprintSlice = append(printSlice, t)\n\t\t\t\t}\n\t\t\t} else if index > m.ActiveIndex {\n\t\t\t\tvar text string\n\t\t\t\tif m.Quitting {\n\t\t\t\t\ttext = cancelStyle.Render(\"CANCELLED \" + stage.Title)\n\t\t\t\t} else {\n\t\t\t\t\ttext = pendingStyle.Render(\"󰚭 \" + stage.Title)\n\t\t\t\t}\n\t\t\t\tprintSlice = append(printSlice, pendingStyle.Render(text))\n\t\t\t}\n\t\t} else {\n\t\t\tprintSlice = append(printSlice, successStyle.Render(\"✔ \"+stage.Success))\n\t\t}\n\t}\n\n\tif m.AllDone {\n\t\tprintSlice = append(printSlice, allDoneStyle.Render(m.FinalMessage))\n\t}\n\n\ts += lipgloss.JoinVertical(lipgloss.Top, printSlice...)\n\n\ts += \"\\n\"\n\n\tif m.Quitting {\n\t\ts += \"\\n\"\n\t}\n\n\treturn appStyle.Render(s)\n}\n\nfunc getLogContainerStyle(m TuiModel) lipgloss.Style {\n\treturn lipgloss.\n\t\tNewStyle().\n\t\tWidth(int(0.98 * float64(m.ViewportWidth))).\n\t\tHeight(0).\n\t\tMarginLeft(int(0.01 * float64(m.ViewportWidth))).\n\t\tBorderStyle(lipgloss.RoundedBorder()).\n\t\tBorderForeground(lipgloss.Color(\"69\")).\n\t\tForeground(lipgloss.Color(\"white\")).Faint(true)\n}\n\nfunc getBannerStyle(m TuiModel) lipgloss.Style {\n\treturn lipgloss.NewStyle().\n\t\tForeground(lipgloss.Color(\"white\")).\n\t\tBackground(lipgloss.Color(\"#414868\")).\n\t\tWidth(m.ViewportWidth).\n\t\tPadding(1).\n\t\tAlign(lipgloss.Center).\n\t\tMarginBottom(1).\n\t\tMarginTop(1)\n}\n\nfunc MakeStage(title string, success string, hasLogs bool) Stage {\n\ts := spinner.New()\n\ts.Style = spinnerStyle\n\ts.Spinner = spinner.MiniDot\n\n\tlogs := []string{}\n\n\treturn Stage{\n\t\tSpinner: s,\n\t\tTitle:   title,\n\t\tSuccess: success,\n\t\tLogs:    logs,\n\t\tHasLogs: hasLogs,\n\t}\n}\n\nfunc SendDockerBuildLogsToTUI(resBody io.ReadCloser, p *tea.Program) {\n\tdec := json.NewDecoder(resBody)\n\tfor {\n\t\tvar msg buildMsg\n\t\tif err := dec.Decode(&msg); err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\t// skip errors here cus shape is wront anyway -> to fix this later\n\t\t// else if err != nil {\n\t\t// fmt.Println(err)\n\t\t// }\n\n\t\tswitch {\n\t\tcase msg.Stream != \"\":\n\t\t\tp.Send(LogMsg{LogLine: msg.Stream})\n\t\tcase msg.Status != \"\":\n\t\t\tif msg.ID != \"\" {\n\t\t\t\t// Yes yes, I'll have a closer look at this later\n\t\t\t\t// if msg.Progress != \"\" {\n\t\t\t\t// p.Send(render.LogMsg{LogLine: fmt.Sprintf(\"[%s] %s %s\\n\", msg.ID, msg.Status, msg.Progress)})\n\t\t\t\t// } else {\n\t\t\t\t// p.Send(LogMsg{LogLine: fmt.Sprintf(\"[%s] %s\\n\", msg.ID, msg.Status)})\n\t\t\t\t// }\n\t\t\t} else {\n\t\t\t\tp.Send(LogMsg{LogLine: msg.Status})\n\t\t\t}\n\t\tcase msg.Error != \"\":\n\t\t\tp.Send(ErrorMsg{ErrorStr: msg.Error})\n\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t}\n\t}\n}\n\nfunc SendLogsToTUI(source io.ReadCloser, p *tea.Program) {\n\tscanner := bufio.NewScanner(source)\n\tfor scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif line != \"\\n\" {\n\t\t\tp.Send(LogMsg{LogLine: scanner.Text() + \"\\n\"})\n\t\t\ttime.Sleep(time.Millisecond * 50)\n\t\t}\n\t}\n}\n\n// WriteStageLogs writes the logs from a specific stage to sidekick.logs.txt\nfunc WriteStageLogs(stage Stage, stageIndex int) error {\n\tif len(stage.Logs) == 0 {\n\t\treturn nil\n\t}\n\n\tfile, err := os.OpenFile(\"sidekick.logs.txt\", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\ttimestamp := time.Now().Format(\"2006-01-02 15:04:05\")\n\theader := fmt.Sprintf(\"\\n=== STAGE %d ERROR LOG - %s ===\\n\", stageIndex+1, timestamp)\n\theader += fmt.Sprintf(\"Stage: %s\\n\", stage.Title)\n\theader += \"=== LOGS START ===\\n\"\n\n\tif _, err := file.WriteString(header); err != nil {\n\t\treturn err\n\t}\n\n\tfor _, log := range stage.Logs {\n\t\tif _, err := file.WriteString(log); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif !strings.HasSuffix(log, \"\\n\") {\n\t\t\tif _, err := file.WriteString(\"\\n\"); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\tfooter := \"=== LOGS END ===\\n\\n\"\n\tif _, err := file.WriteString(footer); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "render/types.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage render\n\nimport (\n\t\"github.com/charmbracelet/bubbles/spinner\"\n\ttea \"github.com/charmbracelet/bubbletea\"\n)\n\ntype LogMsg struct {\n\tLogLine string\n}\n\ntype AllDoneMsg struct {\n\tMessage string\n}\n\ntype ErrorMsg struct {\n\tErrorStr string\n}\ntype NextStageMsg struct{}\n\ntype Stage struct {\n\tTitle    string\n\tSuccess  string\n\tSpinner  spinner.Model\n\tLogs     []string\n\tHasLogs  bool\n\tHasError bool\n}\n\ntype TuiModel struct {\n\ttea.Model\n\tActiveIndex    int\n\tStages         []Stage\n\tQuitting       bool\n\tViewportWidth  int\n\tViewportHeight int\n\tAllDone        bool\n\tBannerMsg      string\n\tFinalMessage   string\n}\n\ntype buildMsg struct {\n\tStream      string `json:\"stream\"`\n\tStatus      string `json:\"status\"`\n\tID          string `json:\"id\"`\n\tProgress    string `json:\"progress\"`\n\tProgressMsg string `json:\"progressDetail\"`\n\tError       string `json:\"error\"`\n}\n"
  },
  {
    "path": "render/utils.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage render\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/charmbracelet/lipgloss\"\n\t\"github.com/charmbracelet/log\"\n\t\"github.com/erikgeiser/promptkit/textinput\"\n\t\"github.com/pterm/pterm\"\n\t\"github.com/pterm/pterm/putils\"\n)\n\nfunc getDefaultTextInput(prompt string, defaultValue string, placeholder string) *textinput.TextInput {\n\tinputPrompt := fmt.Sprintf(\"%s: \", prompt)\n\n\tif defaultValue != \"\" {\n\t\tinputPrompt = fmt.Sprintf(\"%s \\033[3m(default: %s)\\033[0m: \", prompt, defaultValue)\n\t}\n\n\tinput := textinput.New(inputPrompt)\n\tinput.Placeholder = placeholder\n\tinput.InitialValue = \"\"\n\n\tinput.InputTextStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(\"120\"))\n\n\tif defaultValue != \"\" {\n\t\tinput.Validate = nil\n\t}\n\n\treturn input\n}\n\nfunc GenerateTextQuestion(question string, defaultAnswer string, placeholder string) string {\n\tinput := getDefaultTextInput(question, defaultAnswer, placeholder)\n\tuserAnswer, err := input.RunPrompt()\n\n\tif err != nil {\n\t\tGetLogger(log.Options{Prefix: \"Input\"}).Fatalf(\" %s\", err)\n\t}\n\n\tif defaultAnswer != \"\" && userAnswer == \"\" {\n\t\treturn defaultAnswer\n\t}\n\n\treturn userAnswer\n}\n\nfunc GetLogger(options log.Options) *log.Logger {\n\toptions.ReportCaller = false\n\toptions.ReportTimestamp = true\n\toptions.TimeFormat = time.Kitchen\n\n\treturn log.NewWithOptions(os.Stderr, options)\n}\n\nfunc RenderSidekickBig() {\n\tpterm.Println()\n\n\ts, _ := pterm.DefaultBigText.WithLetters(\n\t\tputils.LettersFromStringWithStyle(\"Side\", pterm.FgCyan.ToStyle()),\n\t\tputils.LettersFromStringWithStyle(\"kick\", pterm.FgLightMagenta.ToStyle())).Srender()\n\tpterm.DefaultCenter.Println(s)\n\n}\n\nfunc RenderKeyValidation(resultLines []string, keyHash string, hostname string) {\n\tstartColor := pterm.NewRGB(0, 255, 255)\n\tendColor := pterm.NewRGB(255, 0, 255)\n\n\tpterm.DefaultCenter.Print(keyHash)\n\tfor i := 0; i < len(resultLines[1:]); i++ {\n\t\tfadeFactor := float32(i) / float32(20)\n\t\tcurrentColor := startColor.Fade(0, 1, fadeFactor, endColor)\n\t\tpterm.DefaultCenter.Print(currentColor.Sprint(resultLines[1:][i]))\n\t}\n\tprompt := pterm.DefaultInteractiveContinue\n\n\tpterm.DefaultCenter.Printf(pterm.FgYellow.Sprintf(\"This is the ASCII art and fingerprint of your VPS's public key at %s\", hostname))\n\tpterm.DefaultCenter.Printf(pterm.FgYellow.Sprint(\"Please confirm you want to continue with the connection\"))\n\tpterm.DefaultCenter.Printf(pterm.FgYellow.Sprint(\"Sidekick will add this host/key pair to known_hosts\"))\n\tpterm.Println()\n\n\tprompt.DefaultText = \"Would you like to proceed?\"\n\tprompt.Options = []string{\"yes\", \"no\"}\n\tif result, _ := prompt.Show(); result != \"yes\" {\n\t\tpterm.Error.Println(\"In order to continue, you need to accept this.\")\n\t\tos.Exit(0)\n\t}\n}\n"
  },
  {
    "path": "scripts/destroy-droplets.py",
    "content": "# Copyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n#\n# Licensed under the GNU GPL License, Version 3.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# https://www.gnu.org/licenses/gpl-3.0.en.html\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# Simple script to delete all droplets tagged by sidekick tag after I finish playing around.\n\n#!/usr/bin/env python3\nimport os\nimport time\nimport requests\n\nAPI = \"https://api.digitalocean.com/v2\"\nDROPLETS_TAG = \"sidekick\"\n\ntoken = os.getenv(\"DO_TOKEN\")\nif not token:\n    print(\"❌ Please set DO_TOKEN environment variable\")\n    exit(1)\n\nheaders = {\"Authorization\": f\"Bearer {token}\", \"Content-Type\": \"application/json\"}\n\n\n# destroy all droplets tagged with Sidekick\nname = f\"cheap-sgp1-{int(time.time())}\"\nr = requests.delete(f\"{API}/droplets?tag_name={DROPLETS_TAG}\", headers=headers)\nr.raise_for_status()\n# droplet_id = r.json()[\"droplet\"][\"id\"]\n\nprint(\"✅ All droplets under Sidekick tag have been destoyed\")\n\nexit(1)\n"
  },
  {
    "path": "scripts/make-droplet.py",
    "content": "# Copyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n#\n# Licensed under the GNU GPL License, Version 3.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# https://www.gnu.org/licenses/gpl-3.0.en.html\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# Simple script to make droplets and set them up with sidekick for my testing\n# Sick of using the UI\n\n#!/usr/bin/env python3\nimport os\nimport time\nimport requests\nimport subprocess\n\n\nAPI = \"https://api.digitalocean.com/v2\"\nREGION = \"sgp1\"\nIMAGE = \"ubuntu-24-04-x64\"\nSIZE = \"s-1vcpu-2gb\"\nSSH_KEY_NAME = \"Mac mini-new\"\n\ntoken = os.getenv(\"DO_TOKEN\")\nif not token:\n    print(\"❌ Please set DO_TOKEN environment variable\")\n    exit(1)\n\nheaders = {\"Authorization\": f\"Bearer {token}\", \"Content-Type\": \"application/json\"}\n\n# find SSH key named \"Mac mini\"\nr = requests.get(f\"{API}/account/keys\", headers=headers)\nr.raise_for_status()\nkeys = r.json()[\"ssh_keys\"]\nkey = next((k for k in keys if k[\"name\"] == SSH_KEY_NAME), None)\nif not key:\n    print(f\"❌ No SSH key found named '{SSH_KEY_NAME}'.\")\n    print(\"Available keys:\", [k[\"name\"] for k in keys])\n    exit(1)\n\n# create droplet\nname = f\"cheap-sgp1-{int(time.time())}\"\npayload = {\n    \"name\": name,\n    \"region\": REGION,\n    \"size\": SIZE,\n    \"image\": IMAGE,\n    \"ssh_keys\": [key[\"id\"]],\n    \"backups\": False,\n    \"ipv6\": False,\n    \"tags\": [\"sidekick\"],\n}\nr = requests.post(f\"{API}/droplets\", headers=headers, json=payload)\nr.raise_for_status()\ndroplet_id = r.json()[\"droplet\"][\"id\"]\n\nprint(f\"✅ Droplet created (ID: {droplet_id}), waiting for IP...\")\n\n# wait for IPv4\nfor _ in range(120):  # ~10 minutes\n    time.sleep(5)\n    r = requests.get(f\"{API}/droplets/{droplet_id}\", headers=headers)\n    droplet = r.json()[\"droplet\"]\n    networks = droplet[\"networks\"][\"v4\"]\n    ipv4 = next((n[\"ip_address\"] for n in networks if n[\"type\"] == \"public\"), None)\n    if ipv4:\n        print(ipv4)\n        # print(\"   Giving the VPS time to boot\")\n        # time.sleep(10)\n        # cmd = [\"sidekick\", \"init\", f\"-s={ipv4}\", \"-e=m.mousa@hey.com\", \"-y\"]\n        # subprocess.run(cmd, check=True)\n        exit(0)\n    status = droplet[\"status\"]\n    print(f\"   still {status}...\")\n\nprint(\"❌ Timed out waiting for droplet IP.\")\nexit(1)\n"
  },
  {
    "path": "utils/auth.go",
    "content": "package utils\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\"\n\t\"os\"\n\t\"os/exec\"\n\t\"os/user\"\n\t\"path\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/skeema/knownhosts\"\n\t\"golang.org/x/crypto/ssh\"\n\t\"golang.org/x/crypto/ssh/agent\"\n)\n\nfunc getKeyFilesAuth() ([]ssh.AuthMethod, error) {\n\tuser, err := user.Current()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tsshDir := path.Join(user.HomeDir, \".ssh\")\n\tkeyFiles := []string{\n\t\t\"id_rsa\",\n\t\t\"id_ecdsa\",\n\t\t\"id_ed25519\",\n\t}\n\n\tvar authMethods []ssh.AuthMethod\n\n\tfor _, keyFile := range keyFiles {\n\t\tkeyPath := path.Join(sshDir, keyFile)\n\t\tif _, err := os.Stat(keyPath); os.IsNotExist(err) {\n\t\t\tcontinue\n\t\t}\n\n\t\tprivateKey, err := os.ReadFile(keyPath)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tsigner, err := ssh.ParsePrivateKey(privateKey)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tauthMethods = append(authMethods, ssh.PublicKeys(signer))\n\t}\n\n\treturn authMethods, nil\n}\n\nfunc inspectServerPublicKey(key ssh.PublicKey, hostname string) {\n\tsshKeyCmd := exec.Command(\"sh\", \"-s\", \"-\", string(ssh.MarshalAuthorizedKey(key)))\n\tsshKeyCmd.Stdin = strings.NewReader(sshKeyScript)\n\tresult, sshKeyCmdErr := sshKeyCmd.Output()\n\tif sshKeyCmdErr != nil {\n\t\tpanic(sshKeyCmdErr)\n\t}\n\tresultLines := strings.Split(string(result), \"\\n\")\n\tkeyHash := resultLines[0]\n\n\trender.RenderKeyValidation(resultLines, keyHash, hostname)\n\n}\n\nfunc GetSshClient(server string, sshUser string) (*ssh.Client, error) {\n\tsshPort := \"22\"\n\tsshAgentSock := os.Getenv(\"SSH_AUTH_SOCK\")\n\tif sshAgentSock == \"\" {\n\t\tlog.Fatal(\"No SSH SOCK AVAILABLE\")\n\t\treturn nil, errors.New(\"Error happened connecting to ssh-agent\")\n\t}\n\n\tconn, err := net.Dial(\"unix\", sshAgentSock)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer conn.Close()\n\n\tagentClient := agent.NewClient(conn)\n\n\t// Get auth of standard keys not in agent\n\tauthMethods, _ := getKeyFilesAuth()\n\n\tauthMethods = append(authMethods, ssh.PublicKeysCallback(agentClient.Signers))\n\n\tcb := ssh.HostKeyCallback(func(hostname string, remote net.Addr, key ssh.PublicKey) error {\n\t\tcurrentUser, _ := user.Current()\n\t\tkhPath := fmt.Sprintf(\"%s/.ssh/known_hosts\", currentUser.HomeDir)\n\t\tkh, knErr := knownhosts.NewDB(khPath)\n\t\tif knErr != nil {\n\t\t\treturn knErr\n\t\t}\n\n\t\tinnerCallback := kh.HostKeyCallback()\n\t\terr := innerCallback(hostname, remote, key)\n\t\tif knownhosts.IsHostKeyChanged(err) {\n\t\t\treturn fmt.Errorf(\"REMOTE HOST IDENTIFICATION HAS CHANGED for host %s! This may indicate a MitM attack.\", hostname)\n\t\t} else if knownhosts.IsHostUnknown(err) {\n\t\t\tinspectServerPublicKey(key, hostname)\n\t\t\tf, ferr := os.OpenFile(khPath, os.O_APPEND|os.O_WRONLY, 0600)\n\t\t\tif ferr == nil {\n\t\t\t\tdefer f.Close()\n\t\t\t\tferr = knownhosts.WriteKnownHost(f, hostname, remote, key)\n\t\t\t} else {\n\t\t\t\tlog.Printf(\"Failed to add host %s to known_hosts: %v\\n\", hostname, ferr)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t\treturn err\n\t})\n\n\tvar client *ssh.Client\n\n\t// This error will be thrown when one method/key doesn't work\n\tvar expectedClientErr = errors.New(\"ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain\")\n\tfor _, method := range authMethods {\n\t\tconfig := &ssh.ClientConfig{\n\t\t\tUser:            sshUser,\n\t\t\tAuth:            []ssh.AuthMethod{method},\n\t\t\tHostKeyCallback: cb,\n\t\t\tTimeout:         1 * time.Second,\n\t\t}\n\n\t\tworkingClient, sshClientErr := ssh.Dial(\"tcp\", fmt.Sprintf(\"%s:%s\", server, sshPort), config)\n\t\tif sshClientErr != nil {\n\t\t\tif sshClientErr.Error() != expectedClientErr.Error() {\n\t\t\t\tlog.Fatalf(\"Failed to create ssh client to the server: %v\", sshClientErr)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tclient = workingClient\n\t\tbreak\n\t}\n\tif client == nil {\n\t\treturn nil, errors.New(\"Logging in failed with all available keys for the said user\")\n\t}\n\treturn client, nil\n}\n\nfunc Login(server string, user string) (*ssh.Client, error) {\n\tsshClient, err := GetSshClient(server, user)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn sshClient, nil\n}\n"
  },
  {
    "path": "utils/config.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/spf13/cobra\"\n\t\"gopkg.in/yaml.v3\"\n)\n\nfunc GetSidekickConfigFromCmdContext(cmd *cobra.Command) (*SidekickConfig, error) {\n\tconfig, ok := cmd.Context().Value(\"config\").(*SidekickConfig)\n\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"config not found in cmd context. This is likely a bug in the root cmd initialization.\")\n\t}\n\n\treturn config, nil\n}\n\nfunc (c *SidekickConfig) Save(path string) error {\n\tdata, err := yaml.Marshal(c)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn os.WriteFile(path, data, os.ModePerm)\n}\n\nfunc (c *SidekickConfig) Print() error {\n\tdata, err := yaml.Marshal(c)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = os.Stdout.Write(data)\n\treturn err\n}\n\nfunc (c *SidekickConfig) FindContext(name string) (SidekickContext, error) {\n\tfor _, ctx := range c.Contexts {\n\t\tif ctx.Name == name {\n\t\t\treturn ctx, nil\n\t\t}\n\t}\n\treturn SidekickContext{}, fmt.Errorf(\"context '%s' not found\", name)\n}\n\nfunc (c *SidekickConfig) FindServer(name string) (SidekickServer, error) {\n\tfor _, s := range c.Servers {\n\t\tif s.Name == name {\n\t\t\treturn s, nil\n\t\t}\n\t}\n\treturn SidekickServer{}, fmt.Errorf(\"server '%s' not found\", name)\n}\n\nfunc (c *SidekickConfig) FindServerByContext(ctxName string) (SidekickServer, error) {\n\tctx, err := c.FindContext(ctxName)\n\tif err != nil {\n\t\treturn SidekickServer{}, err\n\t}\n\n\treturn c.FindServer(ctx.Server)\n}\n\nfunc (c *SidekickConfig) AddOrReplaceContext(ctx SidekickContext) {\n\tidx := -1\n\tfor i, elem := range c.Contexts {\n\t\tif elem.Name == ctx.Name {\n\t\t\tidx = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif idx == -1 {\n\t\tc.Contexts = append(c.Contexts, ctx)\n\t} else {\n\t\tc.Contexts[idx] = ctx\n\t}\n}\n\nfunc (c *SidekickConfig) AddOrReplaceServer(s SidekickServer) {\n\tidx := -1\n\tfor i, elem := range c.Servers {\n\t\tif elem.Name == s.Name {\n\t\t\tidx = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif idx == -1 {\n\t\tc.Servers = append(c.Servers, s)\n\t} else {\n\t\tc.Servers[idx] = s\n\t}\n}\n"
  },
  {
    "path": "utils/docker.go",
    "content": "package utils\n\nimport (\n\t\"archive/tar\"\n\t\"bytes\"\n\t\"io\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\nfunc TarDirectoryToReader(dir string) (io.Reader, error) {\n\tbuf := new(bytes.Buffer)\n\ttw := tar.NewWriter(buf)\n\tdefer tw.Close()\n\n\tfilepath.Walk(dir, func(path string, info os.FileInfo, err error) error {\n\t\tif err != nil || info.IsDir() {\n\t\t\treturn err\n\t\t}\n\t\trel, _ := filepath.Rel(dir, path)\n\t\theader, _ := tar.FileInfoHeader(info, rel)\n\t\theader.Name = rel\n\t\ttw.WriteHeader(header)\n\t\tf, _ := os.Open(path)\n\t\tio.Copy(tw, f)\n\t\tf.Close()\n\t\treturn nil\n\t})\n\n\treturn bytes.NewReader(buf.Bytes()), nil\n}\n"
  },
  {
    "path": "utils/scripts.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\nvar sshKeyScript = `\n\t\tpublicKey=$1\n\n\t\techo \"$publicKey\" | ssh-keygen -lvf /dev/stdin \n\t`\n\nvar EnvEncryptionScript = `\n\tPUBKEY=$1\n\tENVFILE=$2\n\n\tsops encrypt --output-type dotenv --age $PUBKEY $ENVFILE > encrypted.env\n\t`\n\nvar DeployAppScript = `\n#!/usr/bin/env bash\nset -euo pipefail\n\nSERVICE=\"$service_name\"\nAPP_PORT=\"$app_port\"\nSLEEP_AFTER_START=3\nHAS_ENV=$has_env\nCOMPOSE_PROJECT=\"sidekick\"\n\n# helper for nicer logs\nlog() { echo \"[$(date +'%T')] $*\"; }\n\n\n# move into service dir (assumes compose file lives in ./<service>/)\nif [[ ! -d \"$SERVICE\" ]]; then\n  log \"ERROR: service directory '$SERVICE' not found.\"\n  exit 2\nfi\n\ncd \"$SERVICE\"\n\n\n# find the old container (oldest for this service)\nold_container_id=$(docker ps -f \"name=${SERVICE}\" -q | tail -n1 || true)\nif [[ -z \"$old_container_id\" ]]; then\n  log \"ERROR: no running containers found for service '${SERVICE}'.\"\n  exit 3\nfi\n\necho $old_container_id\n\n# create a new instance by scaling up to 2 (no deps, don't recreate existing)\nif [ $HAS_ENV ]; then\n\tsops exec-env encrypted.env \"docker compose -p sidekick up -d --no-deps --scale ${SERVICE}=2 --no-recreate ${SERVICE}\"\nelse\n\tdocker compose -p \"$COMPOSE_PROJECT\" up -d --no-deps --scale \"$SERVICE\"=2 --no-recreate \"$SERVICE\"\nfi\n\n# optional small wait for the container to begin initializing\nif (( SLEEP_AFTER_START > 0 )); then\n  log \"Sleeping $SLEEP_AFTER_START seconds for startup...\"\n  sleep \"$SLEEP_AFTER_START\"\nfi\n\n# find newest container for this service\nnew_container_id=$(docker ps -f \"name=${SERVICE}\" -q | head -n1 || true)\nif [[ -z \"$new_container_id\" ]]; then\n  log \"ERROR: failed to detect new container after scaling.\"\n  exit 4\nfi\n\n# safety: ensure new != old\nif [[ \"$new_container_id\" == \"$old_container_id\" ]]; then\n  log \"ERROR: detected the same container as new and old ($new_container_id). Aborting.\"\n  exit 5\nfi\n\n\n# get internal IP of the new container\nnew_container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \"$new_container_id\" || true)\nif [[ -z \"$new_container_ip\" ]]; then\n  log \"ERROR: could not determine IP of new container $new_container_id\"\n  # clean up the new container to avoid leaving an extra one\n  docker rm -f \"$new_container_id\" || true\n  # restore scale to 1 (best effort)\n  docker compose -p \"$COMPOSE_PROJECT\" up -d --scale \"$SERVICE\"=1 --no-recreate \"$SERVICE\" || true\n  exit 6\nfi\n\n\n# health check (preserve your curl options)\nHEALTH_URL=\"http://$new_container_ip:$APP_PORT/\"\nlog \"Health checking $HEALTH_URL (this may retry internally via curl)...\"\n\nif ! curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail \"$HEALTH_URL\" >/dev/null 2>&1; then\n  log \"ERROR: health check failed against $HEALTH_URL\"\n  log \"Removing failed new container $new_container_id and restoring state...\"\n  docker rm -f \"$new_container_id\" || true\n\tif [ $HAS_ENV ]; then\n\t\tsops exec-env encrypted.env \"docker compose -p ${COMPOSE_PROJECT} up -d --scale ${SERVICE}=1 --no-recreate ${SERVICE} || true\"\n\telse \n  \tdocker compose -p \"$COMPOSE_PROJECT\" up -d --scale \"$SERVICE\"=1 --no-recreate \"$SERVICE\" || true\n\tfi\n  exit 7\nfi\n\nlog \"Health check passed. Swapping containers...\"\n\n# stop & remove the old container (now safe)\ndocker stop \"$old_container_id\"\ndocker rm \"$old_container_id\"\n\n# scale back to 1 (remove the spare)\ndocker compose -p \"$COMPOSE_PROJECT\" up -d --scale \"$SERVICE\"=1 --no-recreate \"$SERVICE\"\nif [ $HAS_ENV ]; then\n\tsops exec-env encrypted.env \"docker compose -p ${COMPOSE_PROJECT} up -d --scale ${SERVICE}=1 --no-recreate ${SERVICE}\"\nelse\n\tdocker compose -p \"$COMPOSE_PROJECT\" up -d --scale \"$SERVICE\"=1 --no-recreate \"$SERVICE\"\nfi\n\n# clean up docker system \nlog \"Pruning docker system\"\ndocker system prune -f\n\nexit 0\n\t`\n\nvar CheckGitTreeScript = `\n\tif [[ -z $(git status -s) ]]\n\tthen\n\t  echo \"all good\"\n\telse\n\t  echo \"tree is dirty, please commit changes before running this\"\n\t  exit\n\tfi\n\t`\n\nvar SetupStageScript = `\n#!/usr/bin/env bash\nset -e\n\nwait_for_locks() {\n    echo \"Waiting for apt/dpkg locks...\"\n    while fuser /var/lib/dpkg/lock >/dev/null 2>&1 \\\n       || fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1 \\\n       || fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do\n        sleep 1\n    done\n}\n\necho \"\\033[0;32mUpdating SSH config...\\033[0m\"\nex -s -c 'g/PermitRootLogin/d' -c 'g/AcceptEnv SOPS_*/d' -c 'wq' /etc/ssh/sshd_config\necho 'AcceptEnv SOPS_*' | tee -a /etc/ssh/sshd_config > /dev/null\necho 'PermitRootLogin no' | tee -a /etc/ssh/sshd_config > /dev/null\nsystemctl restart ssh\n\necho \"\\033[0;32mUpdating Packages...\\033[0m\"\nwait_for_locks\nsudo apt-get update -y\n\nwait_for_locks\nsudo apt-get upgrade -y\n\necho \"\\033[0;32mInstalling Necessities ...\\033[0m\"\nwait_for_locks\nsudo apt-get install -y age ca-certificates curl vim\n\necho \"\\033[0;32mInstalling SOPS...\\033[0m\"\ncurl -sLO https://github.com/getsops/sops/releases/download/v3.9.0/sops-v3.9.0.linux.amd64\nsudo mv sops-v3.9.0.linux.amd64 /usr/local/bin/sops\nsudo chmod +x /usr/local/bin/sops\n`\n\nvar TraefikDockerComposeFile = `\nservices:\n  traefik-service:\n    image: traefik:v3.6.1\n    command:\n      - --api.insecure=false\n      - --entrypoints.web.address=:80\n      - --entrypoints.web.http.redirections.entryPoint.to=websecure\n      - --entrypoints.web.http.redirections.entryPoint.scheme=https\n      - --entrypoints.websecure.address=:443\n      - --entrypoints.websecure.http.tls.certresolver=default\n      - --providers.docker.exposedbydefault=false\n      - --certificatesresolvers.default.acme.email=$EMAIL\n      - --certificatesresolvers.default.acme.storage=/ssl-certs/acme.json\n      - --certificatesresolvers.default.acme.httpchallenge.entrypoint=web\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n      # The Web UI (enabled by --api.insecure=true)\n      # - \"8080:8080\"\n    volumes:\n      # So that Traefik can listen to the Docker events\n      - /var/run/docker.sock:/var/run/docker.sock:ro\n      - ./traefik/ssl/:/ssl-certs/\n    networks:\n      - sidekick\n\nnetworks:\n  sidekick:\n    external: true\n`\n"
  },
  {
    "path": "utils/spinner.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\nimport (\n\t\"github.com/pterm/pterm\"\n)\n\nvar stagedSpinner = pterm.DefaultSpinner\n\nfunc GetSpinner() pterm.SpinnerPrinter {\n\tstagedSpinner.Sequence = []string{\".\"}\n\tstagedSpinner.ShowTimer = false\n\treturn stagedSpinner\n}\n"
  },
  {
    "path": "utils/stages.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"strings\"\n)\n\nvar UsersetupStage = CommandsStage{\n\tSpinnerSuccessMessage: \"New user created successfully\",\n\tSpinnerFailMessage:    \"Error creating a new user for the machine\",\n\tCommands: []string{\n\t\t\"sudo useradd -m -s /bin/bash -G sudo sidekick\",\n\t\t`echo \"sidekick ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers.d/sidekick`,\n\t\t\"mkdir -p /home/sidekick/.ssh/\",\n\t\t\"sudo cat /root/.ssh/authorized_keys | sudo tee -a /home/sidekick/.ssh/authorized_keys\",\n\t\t\"sudo chown sidekick:sidekick /home/sidekick/.ssh/authorized_keys\",\n\t\t\"sudo chmod 600 /home/sidekick/.ssh/authorized_keys\",\n\t},\n}\n\nvar SetupStage = CommandsStage{\n\tSpinnerSuccessMessage: \"VPS updated and setup successfully\",\n\tSpinnerFailMessage:    \"Error happened running basic setup commands\",\n\tCommands: []string{\n\t\tfmt.Sprintf(\"echo '%s' | base64 -d > setup.sh\", base64.StdEncoding.EncodeToString([]byte(SetupStageScript))),\n\t\t\"chmod +x ./setup.sh\",\n\t\t\"sudo ./setup.sh\",\n\t\t\"rm ./setup.sh\",\n\t},\n}\n\nvar DockerStage = CommandsStage{\n\tSpinnerSuccessMessage: \"Docker setup successfully\",\n\tSpinnerFailMessage:    \"Error happened during setting up docker\",\n\tCommands: []string{\n\t\t\"sudo apt-get update -y\",\n\t\t\"sudo install -m 0755 -d /etc/apt/keyrings\",\n\t\t\"sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc\",\n\t\t\"sudo chmod a+r /etc/apt/keyrings/docker.asc\",\n\t\t`echo \\\n\t\t\"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \\\n\t\t$(. /etc/os-release && echo \"$VERSION_CODENAME\") stable\" | \\\n\t\tsudo tee /etc/apt/sources.list.d/docker.list > /dev/null`,\n\t\t\"sudo apt-get update -y\",\n\t\t\"sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y\",\n\t\t\"sudo usermod -aG docker sidekick\",\n\t},\n}\n\nfunc GetTraefikStage(email string) CommandsStage {\n\treturn CommandsStage{\n\t\tSpinnerSuccessMessage: \"Successfully setup Traefik\",\n\t\tSpinnerFailMessage:    \"Something went wrong setting up Traefik on your VPS\",\n\t\tCommands: []string{\n\t\t\t\"mkdir traefik\",\n\t\t\tfmt.Sprintf(\"echo '%s' > ./traefik/docker-compose.yml\", strings.Replace(TraefikDockerComposeFile, \"$EMAIL\", email, 1)),\n\t\t\t\"mkdir -p ./traefik/ssl-certs/\",\n\t\t\t\"touch ./traefik/ssl-certs/acme.json\",\n\t\t\t\"chmod 600 ./traefik/ssl-certs/acme.json\",\n\t\t\t\"sudo docker network create sidekick\",\n\t\t\t\"cd traefik && sudo docker compose -p sidekick up -d\",\n\t\t},\n\t}\n}\n"
  },
  {
    "path": "utils/types.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\ntype DependsOn struct {\n\tCondition string `yaml:\"condition\"`\n}\n\ntype Healthcheck struct {\n\tTest     []string `yaml:\"test\"`\n\tInterval string   `yaml:\"interval\"`\n\tTimeout  string   `yaml:\"timeout\"`\n\tRetries  int      `yaml:\"retries\"`\n}\n\ntype DockerService struct {\n\tImage       string               `yaml:\"image\"`\n\tCommand     string               `yaml:\"command,omitempty\"`\n\tRestart     string               `yaml:\"restart,omitempty\"`\n\tPorts       []string             `yaml:\"ports,omitempty\"`\n\tVolumes     []string             `yaml:\"volumes,omitempty\"`\n\tLabels      []string             `yaml:\"labels,omitempty\"`\n\tNetworks    []string             `yaml:\"networks,omitempty\"`\n\tEnvironment []string             `yaml:\"environment,omitempty\"`\n\tDependsOn   map[string]DependsOn `yaml:\"depends_on,omitempty\"`\n\tHealthCheck Healthcheck          `yaml:\"healthcheck,omitempty\"`\n\tEntryPoint  []string             `yaml:\"entrypoint,omitempty\"`\n}\n\ntype DockerNetwork struct {\n\tExternal bool `yaml:\"external\"`\n}\n\ntype DockerComposeFile struct {\n\tServices map[string]DockerService `yaml:\"services\"`\n\tNetworks map[string]DockerNetwork `yaml:\"networks,omitempty\"`\n\tVolumes  map[string]DockerVolume  `yaml:\"volumes,omitempty\"`\n}\n\ntype DockerVolume struct {\n\tDriver string `yaml:\"driver,omitempty\"`\n}\ntype SidekickAppEnvConfig struct {\n\tFile string `yaml:\"file\"`\n\tHash string `yaml:\"hash\"`\n}\n\ntype SidekickPreview struct {\n\tUrl       string `yaml:\"url\"`\n\tImage     string `yaml:\"image\"`\n\tCreatedAt string `yaml:\"createdAt\"`\n}\n\ntype SidekickAppDatabaseBackupConfig struct {\n\tTarget       string `yaml:\"target\"`\n\tBucketName   string `yaml:\"bucketName\"`\n\tBucketPath   string `yaml:\"path\"`\n\tBucketRegion string `yaml:\"region\"`\n\tS3Endpoint   string `yaml:\"s3Endpoint\"`\n}\n\ntype SidekickAppDatabaseConfig struct {\n\tType   string                          `yaml:\"type\"`\n\tDbName string                          `yaml:\"databaseName\"`\n\tBackup SidekickAppDatabaseBackupConfig `yaml:\"backup,omitempty\"`\n}\n\ntype SidekickAppConfig struct {\n\tName           string                     `yaml:\"name\"`\n\tVersion        string                     `yaml:\"version\"`\n\tImage          string                     `yaml:\"image\"`\n\tUrl            string                     `yaml:\"url\"`\n\tPort           uint64                     `yaml:\"port\"`\n\tCreatedAt      string                     `yaml:\"createdAt\"`\n\tEnv            SidekickAppEnvConfig       `yaml:\"env,omitempty\"`\n\tDatabaseConfig SidekickAppDatabaseConfig  `yaml:\"database,omitempty\"`\n\tPreviewEnvs    map[string]SidekickPreview `yaml:\"previewEnvs,omitempty\"`\n\tServer         string                     `yaml:\"server\"`\n}\ntype EnvVar map[string]string\n\ntype SidekickConfig struct {\n\tVersion        string            `yaml:\"version\"`\n\tServers        []SidekickServer  `yaml:\"servers\"`\n\tContexts       []SidekickContext `yaml:\"contexts\"`\n\tCurrentContext string            `yaml:\"current-context\"`\n}\n\ntype SidekickServer struct {\n\tName       string `yaml:\"name\"`\n\tAddress    string `yaml:\"serveraddress\"`\n\tDistro     string `yaml:\"distro\"`\n\tPlatformId string `yaml:\"platformid\"`\n\tCertEmail  string `yaml:\"certemail\"`\n\tPublicKey  string `yaml:\"publickey\"`\n\tSecretKey  string `yaml:\"secretkey\"`\n}\n\ntype SidekickContext struct {\n\tName   string `yaml:\"name\"`\n\tServer string `yaml:\"server\"`\n}\n"
  },
  {
    "path": "utils/utils.go",
    "content": "/*\nCopyright © 2024 Mahmoud Mousa <m.mousa@hey.com>\n\nLicensed under the GNU GPL License, Version 3.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.gnu.org/licenses/gpl-3.0.en.html\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\npackage utils\n\nimport (\n\t\"bufio\"\n\t\"crypto/md5\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"regexp\"\n\t\"strings\"\n\t\"time\"\n\n\ttea \"github.com/charmbracelet/bubbletea\"\n\t\"github.com/charmbracelet/log\"\n\t\"github.com/joho/godotenv\"\n\t\"github.com/mightymoud/sidekick/render\"\n\t\"github.com/pterm/pterm\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/viper\"\n\t\"golang.org/x/crypto/ssh\"\n\t\"gopkg.in/yaml.v3\"\n)\n\ntype CommandsStage struct {\n\tCommands              []string\n\tSpinnerSuccessMessage string\n\tSpinnerFailMessage    string\n}\n\nfunc RunCommand(client *ssh.Client, cmd string) (chan string, chan string, error) {\n\tsession, err := client.NewSession()\n\terrChannel := make(chan string)\n\tstdOutChannel := make(chan string)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create session: %s\", err)\n\t}\n\tdefer session.Close()\n\t// Need to hook into the pipe of output coming from that session\n\tstdoutReader, err := session.StdoutPipe()\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting stdout reader: %s\", err)\n\t}\n\tstderrReader, err := session.StderrPipe()\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting stderr reader: %s\", err)\n\t}\n\n\t// make a scanner of that reader that will read as we get new stuff\n\tstdoutScanner := bufio.NewScanner(stdoutReader)\n\tstderrScanner := bufio.NewScanner(stderrReader)\n\n\t// start separate go routines to read from the pipes and print out\n\tgo func() {\n\t\tfor stdoutScanner.Scan() {\n\t\t\tstdOutChannel <- stdoutScanner.Text()\n\t\t\t// fmt.Printf(\"\\033[34m[STDOUT]\\033[0m %s\\n\", stdoutScanner.Text())\n\t\t}\n\t}()\n\n\tgo func() {\n\t\tfor stderrScanner.Scan() {\n\t\t\terrChannel <- stderrScanner.Text()\n\t\t\t// fmt.Printf(\"\\n\\033[31m[STDERR]\\033[0m %s\\n\", stderrScanner.Text())\n\t\t}\n\t}()\n\n\tif err := session.Run(cmd); err != nil {\n\t\tdefer session.Close()\n\t\terrString := <-errChannel\n\t\treturn nil, nil, fmt.Errorf(\"error running command - %s: - %s\", cmd, errString)\n\t}\n\n\ttime.Sleep(time.Millisecond * 500)\n\treturn stdOutChannel, errChannel, nil\n}\n\nfunc RunCommandWithTUIHook(client *ssh.Client, cmd string, p *tea.Program, envVars ...EnvVar) {\n\tsession, err := client.NewSession()\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create session: %s\", err)\n\t}\n\tdefer session.Close()\n\n\tfor _, env := range envVars {\n\t\tfor key, value := range env {\n\t\t\terr := session.Setenv(key, value)\n\t\t\tif err != nil {\n\t\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"error is:%s\", err)})\n\t\t\t}\n\t\t}\n\t}\n\n\tstdoutReader, err := session.StdoutPipe()\n\tif err != nil {\n\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"error running command - %s: - %s\", cmd, err) + err.Error()})\n\t}\n\tstderrReader, err := session.StderrPipe()\n\tif err != nil {\n\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"error running command - %s: - %s\", cmd, err) + err.Error()})\n\t}\n\n\tstdoutScanner := bufio.NewScanner(stdoutReader)\n\tstderrScanner := bufio.NewScanner(stderrReader)\n\n\tif err := session.Start(cmd); err != nil {\n\t\ttime.Sleep(time.Millisecond * 100)\n\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"error running command - %s: - %s\", cmd, err) + err.Error()})\n\t}\n\n\tfor stdoutScanner.Scan() {\n\t\tp.Send(render.LogMsg{LogLine: stdoutScanner.Text() + \"\\n\"})\n\t\ttime.Sleep(time.Millisecond * 50)\n\t}\n\n\tfor stderrScanner.Scan() {\n\t\tp.Send(render.LogMsg{LogLine: stderrScanner.Text() + \"\\n\"})\n\t\ttime.Sleep(time.Millisecond * 50)\n\t}\n\n\tif err := session.Wait(); err != nil {\n\t\tif len(cmd) >= 80 {\n\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"Failed with following error - %s\", err) + err.Error()})\n\t\t} else {\n\t\t\tp.Send(render.ErrorMsg{ErrorStr: fmt.Sprintf(\"error running command - %s: - %s\", cmd, err) + err.Error()})\n\t\t}\n\t}\n}\n\nfunc RunCommands(client *ssh.Client, commands []string) error {\n\tfor _, cmd := range commands {\n\t\t_, _, err := RunCommand(client, cmd)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t}\n\treturn nil\n}\n\nfunc RunCommandsWithTUIHook(client *ssh.Client, commands []string, p *tea.Program) error {\n\tfor _, cmd := range commands {\n\t\tRunCommandWithTUIHook(client, cmd, p)\n\t}\n\treturn nil\n}\n\nfunc RunStage(client *ssh.Client, stage CommandsStage) error {\n\tif err := RunCommands(client, stage.Commands); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc IsValidIPAddress(ip string) bool {\n\tconst ipPattern = `\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b`\n\n\tre := regexp.MustCompile(ipPattern)\n\n\treturn re.MatchString(ip)\n}\n\nfunc FileExists(filename string) bool {\n\t_, err := os.Stat(filename)\n\tif err == nil {\n\t\treturn true\n\t}\n\tif os.IsNotExist(err) {\n\t\treturn false\n\t}\n\treturn false\n}\n\nfunc ViperInit() error {\n\thome, err := os.UserHomeDir()\n\tcobra.CheckErr(err)\n\n\tconfigPath := fmt.Sprintf(\"%s/.config/sidekick\", home)\n\n\tviper.AddConfigPath(configPath)\n\tviper.SetConfigType(\"yaml\")\n\tviper.SetConfigName(\"default\")\n\terr = viper.ReadInConfig()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc LoadAppConfig() (SidekickAppConfig, error) {\n\tif !FileExists(\"./sidekick.yml\") {\n\t\treturn SidekickAppConfig{}, errors.New(\"Sidekick app config not found. Please run sidekick launch first\")\n\t}\n\tappConfigFile := SidekickAppConfig{}\n\tcontent, err := os.ReadFile(\"./sidekick.yml\")\n\tif err != nil {\n\t\tpterm.Error.Println(\"Unable to process your project config\")\n\t\tos.Exit(1)\n\t}\n\tif err := yaml.Unmarshal(content, &appConfigFile); err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn appConfigFile, nil\n}\n\nfunc HandleEnvFile(envFileName string, dockerEnvProperty *[]string, envFileChecksum *string, publicKey string) error {\n\tenvFile, envFileErr := os.Open(fmt.Sprintf(\"./%s\", envFileName))\n\tif envFileErr != nil {\n\t\treturn envFileErr\n\t}\n\tenvMap, envParseErr := godotenv.Parse(envFile)\n\tif envParseErr != nil {\n\t\treturn envParseErr\n\t}\n\n\tfor key := range envMap {\n\t\tif strings.HasPrefix(key, \"_\") {\n\t\t\tcontinue\n\t\t}\n\t\t*dockerEnvProperty = append(*dockerEnvProperty, fmt.Sprintf(\"%s=${%s}\", key, key))\n\t}\n\t// calculate and store the hash of env file to re-encrypt later on when changed\n\tenvFileContent, _ := godotenv.Marshal(envMap)\n\t*envFileChecksum = fmt.Sprintf(\"%x\", md5.Sum([]byte(envFileContent)))\n\tenvCmd := exec.Command(\"sops\",\n\t\t\"encrypt\",\n\t\t\"--output-type\", \"dotenv\",\n\t\t\"--age\", publicKey,\n\t\tfmt.Sprintf(\"./%s\", envFileName),\n\t)\n\toutfile, err := os.Create(\"encrypted.env\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outfile.Close()\n\tenvCmd.Stdout = outfile\n\tif envCmdErr := envCmd.Run(); envCmdErr != nil {\n\t\treturn envCmdErr\n\t}\n\treturn nil\n}\n\nfunc WriteEnvFile(filename string, env map[string]string) error {\n\tf, err := os.Open(filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error openign file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tfor key, value := range env {\n\t\t// Check if the value contains spaces or special characters\n\t\t// and quote it if needed.  This is important for robustness.\n\t\tif strings.ContainsAny(value, \" \\t\\n\\r\\\"\") {\n\t\t\tvalue = fmt.Sprintf(\"\\\"%s\\\"\", strings.ReplaceAll(value, \"\\\"\", \"\\\\\\\"\")) // Escape inner quotes\n\t\t}\n\t\tif _, err := f.WriteString(fmt.Sprintf(\"%s=%s\\n\", key, value)); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to file: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "utils/utils_test.go",
    "content": "package utils_test\n\nimport (\n\t\"crypto/md5\"\n\t\"fmt\"\n\t\"os\"\n\t\"testing\"\n\n\t\"github.com/joho/godotenv\"\n\t\"github.com/mightymoud/sidekick/utils\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc TestHandleEnvFile(t *testing.T) {\n\tenvFileName := \"test.env\"\n\tdockerEnvProperty := []string{}\n\tvar envFileChecksum string\n\n\tenvContent := \"KEY1=value1\\nKEY2=value2\"\n\n\terr := os.WriteFile(envFileName, []byte(envContent), 0644)\n\tassert.NoError(t, err)\n\tdefer os.Remove(envFileName)\n\tdefer os.Remove(\"encrypted.env\")\n\tenvFile, envFileErr := os.Open(fmt.Sprintf(\"./%s\", envFileName))\n\tassert.NoError(t, envFileErr)\n\n\tenvMap, envParseErr := godotenv.Parse(envFile)\n\tassert.NoError(t, envParseErr)\n\tenvFileContent, envMarshalErr := godotenv.Marshal(envMap)\n\tassert.NoError(t, envMarshalErr)\n\n\tpub := \"age1lgjx644dkpj2nas84pfe4dsd96tph8yxhgf6zfh58kqw06qycavsz00rzm\"\n\terr = utils.HandleEnvFile(envFileName, &dockerEnvProperty, &envFileChecksum, pub)\n\tassert.NoError(t, err)\n\n\tassert.Contains(t, dockerEnvProperty, \"KEY2=${KEY2}\")\n\tassert.Contains(t, dockerEnvProperty, \"KEY1=${KEY1}\")\n\n\texpectedChecksum := fmt.Sprintf(\"%x\", md5.Sum([]byte(envFileContent)))\n\tassert.Equal(t, expectedChecksum, envFileChecksum)\n}\nfunc TestLoadAppConfig(t *testing.T) {\n\tconfigContent := `\nname: test\nversion: V1\nimage: \"\"\nurl: MOCK_URL\nport: 3000\ncreatedAt: Mon Nov 11 21:42:50 KST 2024\n`\n\terr := os.WriteFile(\"sidekick.yml\", []byte(configContent), 0644)\n\tassert.NoError(t, err)\n\tdefer os.Remove(\"sidekick.yml\")\n\n\tappConfig, err := utils.LoadAppConfig()\n\tassert.NoError(t, err)\n\n\tassert.Equal(t, \"test\", appConfig.Name)\n\tassert.Equal(t, \"V1\", appConfig.Version)\n\tassert.Equal(t, \"MOCK_URL\", appConfig.Url)\n}\n\nfunc TestLoadAppConfig_FileNotFound(t *testing.T) {\n\tos.Remove(\"sidekick.yml\")\n\n\t_, err := utils.LoadAppConfig()\n\tassert.Error(t, err)\n\tassert.Equal(t, \"Sidekick app config not found. Please run sidekick launch first\", err.Error())\n}\n"
  }
]