├── .all-contributorsrc
├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .gitmodules
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── doc.go
├── docli.go
├── docs
├── config.yml
├── content
│ ├── _index.md
│ ├── docs
│ │ ├── feedback
│ │ │ └── index.md
│ │ ├── installation
│ │ │ └── index.md
│ │ ├── tutorial
│ │ │ └── index.md
│ │ └── unsupported-features
│ │ │ └── index.md
│ └── menu
│ │ └── index.md
├── layouts
│ └── partials
│ │ └── docs
│ │ ├── brand.html
│ │ └── inject
│ │ ├── head.html
│ │ └── menu-after.html
├── public
│ ├── 404.html
│ ├── avatar.png
│ ├── book.min.29d743ffb6d61ecbfc9bb21b7eab17d63b577d4bd547c3f095addb1c793ab1b1.css
│ ├── book.min.95d69eb6bad8b9707ff2b5d8d9e31ce70a1b84f2ed7ffaf665ffcf00aa7993bd.css
│ ├── book.min.dd0f25ca71c9192648088113f8cdb8d63a2fbebc903768fb79ee24bc87357c98.css
│ ├── docs
│ │ ├── feedback
│ │ │ └── index.html
│ │ ├── index.html
│ │ ├── index.xml
│ │ ├── installation
│ │ │ └── index.html
│ │ ├── license
│ │ │ └── index.html
│ │ ├── tutorial
│ │ │ └── index.html
│ │ └── unsupported-features
│ │ │ └── index.html
│ ├── en.search-data.min.2e4816fcf335f19843d3e87d03c3ffbb98d6cc8dac625000b49e5493642d1265.json
│ ├── en.search-data.min.b7c721dd1bec1696af0abc4157baf0d185c534cdcc71d9a1ce52329b7ec6da43.json
│ ├── en.search-data.min.e590e8c46a909cea153ae2ea57829c489ba98d785de4512d3fc3650c9ee2e0ad.json
│ ├── en.search-data.min.eede715b4a6d62ae010148ceeaeb809fca5a0b0d743a280dd9c411fecf86d5dd.json
│ ├── en.search.min.055211035e76540870f517153dc4d92a1bb55b5d44ef3c659de97821b47f221e.js
│ ├── en.search.min.0cd04d6a90707e870433c7aac59a3f0ecde0f01ccd88395162b53d7d5d87535c.js
│ ├── en.search.min.551ad11ad4c428fd22af05a79645e08ed16760f970190c22749f37b3ff76b790.js
│ ├── en.search.min.ccd1416a9f4d5c223125235f4930c17094838c6bbc76296c7b6380ea70d0061f.js
│ ├── favicon.png
│ ├── favicon.svg
│ ├── flexsearch.min.js
│ ├── fonts
│ │ ├── roboto-mono-v13-latin-regular.woff
│ │ ├── roboto-mono-v13-latin-regular.woff2
│ │ ├── roboto-v27-latin-700.woff
│ │ ├── roboto-v27-latin-700.woff2
│ │ ├── roboto-v27-latin-regular.woff
│ │ └── roboto-v27-latin-regular.woff2
│ ├── index.html
│ ├── index.xml
│ ├── katex
│ │ ├── auto-render.min.js
│ │ ├── fonts
│ │ │ ├── KaTeX_AMS-Regular.ttf
│ │ │ ├── KaTeX_AMS-Regular.woff
│ │ │ ├── KaTeX_AMS-Regular.woff2
│ │ │ ├── KaTeX_Caligraphic-Bold.ttf
│ │ │ ├── KaTeX_Caligraphic-Bold.woff
│ │ │ ├── KaTeX_Caligraphic-Bold.woff2
│ │ │ ├── KaTeX_Caligraphic-Regular.ttf
│ │ │ ├── KaTeX_Caligraphic-Regular.woff
│ │ │ ├── KaTeX_Caligraphic-Regular.woff2
│ │ │ ├── KaTeX_Fraktur-Bold.ttf
│ │ │ ├── KaTeX_Fraktur-Bold.woff
│ │ │ ├── KaTeX_Fraktur-Bold.woff2
│ │ │ ├── KaTeX_Fraktur-Regular.ttf
│ │ │ ├── KaTeX_Fraktur-Regular.woff
│ │ │ ├── KaTeX_Fraktur-Regular.woff2
│ │ │ ├── KaTeX_Main-Bold.ttf
│ │ │ ├── KaTeX_Main-Bold.woff
│ │ │ ├── KaTeX_Main-Bold.woff2
│ │ │ ├── KaTeX_Main-BoldItalic.ttf
│ │ │ ├── KaTeX_Main-BoldItalic.woff
│ │ │ ├── KaTeX_Main-BoldItalic.woff2
│ │ │ ├── KaTeX_Main-Italic.ttf
│ │ │ ├── KaTeX_Main-Italic.woff
│ │ │ ├── KaTeX_Main-Italic.woff2
│ │ │ ├── KaTeX_Main-Regular.ttf
│ │ │ ├── KaTeX_Main-Regular.woff
│ │ │ ├── KaTeX_Main-Regular.woff2
│ │ │ ├── KaTeX_Math-BoldItalic.ttf
│ │ │ ├── KaTeX_Math-BoldItalic.woff
│ │ │ ├── KaTeX_Math-BoldItalic.woff2
│ │ │ ├── KaTeX_Math-Italic.ttf
│ │ │ ├── KaTeX_Math-Italic.woff
│ │ │ ├── KaTeX_Math-Italic.woff2
│ │ │ ├── KaTeX_SansSerif-Bold.ttf
│ │ │ ├── KaTeX_SansSerif-Bold.woff
│ │ │ ├── KaTeX_SansSerif-Bold.woff2
│ │ │ ├── KaTeX_SansSerif-Italic.ttf
│ │ │ ├── KaTeX_SansSerif-Italic.woff
│ │ │ ├── KaTeX_SansSerif-Italic.woff2
│ │ │ ├── KaTeX_SansSerif-Regular.ttf
│ │ │ ├── KaTeX_SansSerif-Regular.woff
│ │ │ ├── KaTeX_SansSerif-Regular.woff2
│ │ │ ├── KaTeX_Script-Regular.ttf
│ │ │ ├── KaTeX_Script-Regular.woff
│ │ │ ├── KaTeX_Script-Regular.woff2
│ │ │ ├── KaTeX_Size1-Regular.ttf
│ │ │ ├── KaTeX_Size1-Regular.woff
│ │ │ ├── KaTeX_Size1-Regular.woff2
│ │ │ ├── KaTeX_Size2-Regular.ttf
│ │ │ ├── KaTeX_Size2-Regular.woff
│ │ │ ├── KaTeX_Size2-Regular.woff2
│ │ │ ├── KaTeX_Size3-Regular.ttf
│ │ │ ├── KaTeX_Size3-Regular.woff
│ │ │ ├── KaTeX_Size3-Regular.woff2
│ │ │ ├── KaTeX_Size4-Regular.ttf
│ │ │ ├── KaTeX_Size4-Regular.woff
│ │ │ ├── KaTeX_Size4-Regular.woff2
│ │ │ ├── KaTeX_Typewriter-Regular.ttf
│ │ │ ├── KaTeX_Typewriter-Regular.woff
│ │ │ └── KaTeX_Typewriter-Regular.woff2
│ │ ├── katex.min.css
│ │ └── katex.min.js
│ ├── manifest.json
│ ├── mermaid.min.js
│ ├── normalize.min.css
│ ├── sitemap.xml
│ └── svg
│ │ ├── calendar.svg
│ │ ├── code-fork.svg
│ │ ├── code-merge.svg
│ │ ├── edit.svg
│ │ ├── menu.svg
│ │ ├── toc.svg
│ │ └── translate.svg
├── resources
│ └── _gen
│ │ └── assets
│ │ └── scss
│ │ ├── book.scss_48b060fe05b0a273d182ef83c0605941.content
│ │ ├── book.scss_48b060fe05b0a273d182ef83c0605941.json
│ │ ├── book.scss_50fc8c04e12a2f59027287995557ceff.content
│ │ └── book.scss_50fc8c04e12a2f59027287995557ceff.json
└── static
│ └── avatar.png
├── examples
└── git
│ ├── cmd
│ ├── clone.go
│ └── root.go
│ └── main.go
├── go.mod
├── go.sum
├── internal
└── reger
│ └── reger.go
├── pkg
├── args
│ ├── args.go
│ ├── args_test.go
│ ├── command.go
│ ├── errors.go
│ ├── grammar.go
│ └── grammar_test.go
└── docstring
│ ├── docstring.go
│ ├── docstring_test.go
│ ├── grammar.go
│ └── grammar_test.go
└── revive.toml
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "docli",
3 | "projectOwner": "celicoo",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "imageSize": 75,
10 | "commit": false,
11 | "contributors": [
12 | {
13 | "login": "ri0t",
14 | "name": "riot",
15 | "avatar_url": "https://avatars0.githubusercontent.com/u/1938065?v=4",
16 | "profile": "https://github.com/ri0t",
17 | "contributions": [
18 | "doc"
19 | ]
20 | }
21 | ],
22 | "contributorsPerLine": 7
23 | }
24 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
7 |
8 | ## Description
9 |
13 |
14 | ## Expected behavior
15 |
16 |
20 |
21 | ## Actual behavior
22 |
26 |
27 | ## Possible Fix
28 |
31 |
32 | ## Your environment
33 |
34 | * Version used:
35 | * Link to your project:
36 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Checklist:
6 |
10 | - [ ] I have added tests to cover my changes
11 | - [ ] All new and existing tests passed
12 | - [ ] My change requires a change to the documentation
13 | - [ ] I have updated the documentation accordingly
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins.
2 | *.exe
3 | *.exe~
4 | *.dll
5 | *.so
6 | *.dylib
7 |
8 | # Test binary, built with `go test -c`.
9 | *.test
10 |
11 | # Output of the go coverage tool, specifically when used with LiteIDE.
12 | *.out
13 |
14 | # Dependency directories.
15 | vendor/
16 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "docs/themes/book"]
2 | path = docs/themes/book
3 | url = https://github.com/alex-shpak/hugo-book
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | env:
4 | - PACKAGES=$(go list ./... | grep -v /examples/)
5 |
6 | go:
7 | - 1.13.x
8 |
9 | git:
10 | depth: 1
11 |
12 | matrix:
13 | fast_finish: true
14 |
15 | before_install:
16 | - go get github.com/mgechev/revive
17 |
18 | install:
19 | - go get -t -v $PACKAGES
20 |
21 | script:
22 | - test -z "$(revive -config revive.toml $PACKAGES)"
23 | - go test -v -race -covermode=atomic -coverprofile=coverage.txt $PACKAGES
24 | # - go vet ./...
25 |
26 | after_success:
27 | - bash <(curl -s https://codecov.io/bash)
28 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | me@celicoo.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | Docli is a declarative language for describing command-line interfaces in Go programs. It cuts down the boilerplate to the bare minimum so you're free to move on to the actual reason you're making the app in the first place.
21 |
22 | Docli is 100% inspired by [docopt](https://github.com/docopt/docopt.go).
23 |
24 | - [Documentation](https://docli.dev)
25 | - [Tutorial](https://docli.dev/docs/tutorial)
26 | - [Bug tracker](https://github.com/celicoo/docli/issues)
27 |
28 | ## Contributors
29 |
30 | Thanks go to these wonderful people:
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
39 |
--------------------------------------------------------------------------------
/doc.go:
--------------------------------------------------------------------------------
1 | // Package docli is declarative language for describing command-line interfaces
2 | // in Go programs. It cuts down the boilerplate to the very minimum, so you're
3 | // free to move on to the reason why you're making the app in the first place.
4 | // Docli is 100% inspired by docopt.
5 | package docli
6 |
--------------------------------------------------------------------------------
/docli.go:
--------------------------------------------------------------------------------
1 | package docli
2 |
3 | import "github.com/celicoo/docli/v2/pkg/args"
4 |
5 | // Args returns the AST of the command-line arguments, starting after the
6 | // program name.
7 | func Args() args.Args {
8 | return args.Parse()
9 | }
10 |
--------------------------------------------------------------------------------
/docs/config.yml:
--------------------------------------------------------------------------------
1 | baseURL: https://docli.dev
2 | languageCode: en-us
3 | title: Docli
4 | googleAnalytics: UA-135349489-1
5 | theme: book
6 | enableGitInfo: true
7 | enableEmoji: true
8 | disableKinds:
9 | - taxonomy
10 | - taxonomyTerm
11 |
12 | params:
13 | bookEditPath: edit/master/docs/content
14 | bookMenuBundle: /menu
15 | bookRepo: https://github.com/celicoo/docli
16 | bookTheme: auto
17 | logo: /avatar.png
18 |
--------------------------------------------------------------------------------
/docs/content/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Introduction
3 | type: docs
4 | ---
5 |
6 | # Introduction
7 |
8 | [](https://app.travis-ci.com/celicoo/docli)
9 | [](https://godoc.org/github.com/celicoo/docli/v2)
10 |
11 | Welcome to the official Docli documentation. Here you'll learn how to use Docli for your next project.
12 |
13 | ## What is Docli?
14 |
15 | Docli is a declarative language for describing command-line interfaces in Go programs. It cuts down the boilerplate to the bare minimum so you're free to move on to the actual reason you're making the app in the first place.
16 |
17 | Docli is 100% inspired by [docopt](https://github.com/docopt/docopt.go).
18 |
19 | ## Getting started
20 |
21 | The easiest way to get started with Docli is by following the [Tutorial]({{< relref "/docs/tutorial" >}}). To make the most out of it, you should have a working knowledge of:
22 |
23 | - [Errors](https://gobyexample.com/errors)
24 | - [Interfaces](https://gobyexample.com/interfaces)
25 | - [Pointers](https://gobyexample.com/pointers)
26 | - [Structs](https://gobyexample.com/structs)
27 |
28 | Good luck.
29 |
--------------------------------------------------------------------------------
/docs/content/docs/feedback/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Feedback
3 | ---
4 |
5 | # Feedback
6 |
7 | Feel free to send me feedback on [Twitter](https://twitter.com/celicoo) or [file an issue](https://github.com/celicoo/docli/issues). Feature requests and contributions are always welcome.
8 |
--------------------------------------------------------------------------------
/docs/content/docs/installation/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Installation
3 | ---
4 |
5 | # Installation
6 |
7 | Currently, **Docli requires Go version 1.13 or greater**. You can install Docli with a single command using `go get`, the Go package manager. Type this into your terminal:
8 |
9 | {{}}
10 | $ go get -u github.com/celicoo/docli/v2@latest
11 | {{}}
12 |
13 | Don't have Go installed? [Learn how to install Go here](https://golang.org/doc/install).
14 |
--------------------------------------------------------------------------------
/docs/content/docs/tutorial/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Tutorial
3 | ---
4 |
5 | # Tutorial
6 |
7 | Welcome to the Docli Tutorial! Here you'll be introduced to the key Docli concepts. If you get stuck at any point in
8 | the process, feel free to [download](https://github.com/celicoo/docli/tree/main/examples/git) a working example of the
9 | completed CLI app.
10 |
11 | ## Confirming that Docli is installed
12 |
13 | Before starting the tutorial, let's make sure that you have Docli installed. Go ahead and create a `main.go` file and paste the following content inside:
14 |
15 | {{}}
16 | package main
17 |
18 | import (
19 | "github.com/alecthomas/repr"
20 | "github.com/celicoo/docli/v2"
21 | )
22 |
23 | func main() {
24 | args := docli.Args()
25 | repr.Println(args)
26 | }
27 | {{}}
28 |
29 | Now build and run it:
30 |
31 | {{}}
32 | $ go build
33 | $ ./main
34 |
35 | docli.args{
36 | }
37 | {{}}
38 |
39 | **Note**: the output is the [Abstract Syntax Structure](https://en.wikipedia.org/wiki/Abstract_syntax_tree) of the command-line arguments, and it's empty because you didn't pass any arguments. If you run it again passing arguments you should see a different output.
40 |
41 | ## Creating a new CLI app
42 |
43 | ### Directory structure
44 |
45 | If you like [Cobra](http://cobra.dev), you'll feel at home with this. While you're welcome to provide your own organization, typically a Docli-based app will follow the following directory structure:
46 |
47 | {{< highlight text >}}
48 | ▾ app/
49 | ▾ cmd/
50 | root.go
51 | main.go
52 | {{< /highlight >}}
53 |
54 | Go ahead and create the above structure, but instead of `app`, let's name the root directory to `git`.
55 |
56 | #### **app/**
57 |
58 | This is the root of our app. The `main.go` file goes into this directory and it's responsible for calling the function that initializes Docli:
59 |
60 | {{}}
61 | package main
62 |
63 | import "/git"
64 |
65 | func main() {
66 | cmd.Execute()
67 | }
68 | {{}}
69 |
70 | **Note**: Make sure to replace the `` placeholder.
71 |
72 | #### **cmd/**
73 |
74 | This is where the commands are stored. The `root.go` is responsible for the logic of the **root command** and the `Execute()` function:
75 |
76 | {{}}
77 | package cmd
78 |
79 | const version = "0.0.1"
80 |
81 | type Git struct {}
82 |
83 | func (g *Git) Doc() string {
84 | return ""
85 | }
86 |
87 | func (g *Git) Run() {
88 | }
89 |
90 | func (g *Git) Help() {
91 | }
92 |
93 | func (g *Git) Error(err error) {
94 | }
95 |
96 | func Execute() {
97 | }
98 | {{}}
99 |
100 | The `Git` struct represents the root command in our CLI app and it must implement the [docli.command](/) interface.
101 |
102 | ### Writing the docstring
103 |
104 | Like YAML or Python, the docstring is a line-oriented language that uses indentation to define structure. Lines beginning with either spaces or tabs are used to register arguments and commands (commands are explained a little later in the tutorial). These arguments and commands can have letters of any language, numbers, and dashes.
105 |
106 | Let’s go back to the root.go file and replace the [Doc()](/) method of our Git struct with:
107 |
108 | {{}}
109 | func (g *Git) Doc() string {
110 | return `usage: git
111 |
112 | commands:
113 | c, clone clone a repository into a new directory
114 |
115 | arguments:
116 |
117 | v, --version print version
118 |
119 | Use "git help" for more information about the .`
120 | }
121 | {{}}
122 |
123 | By convention, dashes are used in front of arguments, but not commands. You can use this convention with Docli, but it's not necessary.
124 |
125 | ### Accessing command-line argument values
126 |
127 | Now that we’ve registered the arguments and commands in the docstring, we’ll need to define them as fields in the `Git` struct, so we can access their values. Fields that represent arguments will be primitive types and those that represent commands will be user-defined types that implement the [docli.command](/) interface, just like the root command does.
128 |
129 | Regardless of how many aliases your arguments or commands have , you'll only need to (and only should) define one field in the struct. We suggest using the longer identifier, but you can use whichever you’d like.
130 |
131 | In our example, we have one command and one argument, and each has two identifiers. Let’s add these to our `Git` struct:
132 |
133 | {{}}
134 | type Git struct {
135 | Clone Clone
136 | Version bool
137 | }
138 | {{}}
139 |
140 | For every command, you’ll need to create a file to hold the type that represents the command. In our example, the Clone field represents the `clone` command, so we need to create a file that holds this type. Let's go ahead and create the `clone.go` file inside the `cmd` directory and paste the following code inside:
141 |
142 | {{}}
143 | package cmd
144 |
145 | import (
146 | "fmt"
147 | "log"
148 |
149 | "github.com/alecthomas/repr"
150 | )
151 |
152 | type Clone struct {
153 | Repository,
154 | Directory string
155 | Verbose,
156 | Quiet,
157 | Progress,
158 | NoCheckout,
159 | Bare,
160 | Mirror,
161 | Local,
162 | NoHardlinks,
163 | Shared bool
164 | RecurseSubmodules string
165 | Jobs int
166 | Template,
167 | Reference,
168 | ReferenceIfAble string
169 | Dissociate bool
170 | Origin,
171 | Branch,
172 | UploadPack string
173 | Depth int
174 | ShallowSince,
175 | ShallowExclude string
176 | SingleBranch,
177 | NoTags,
178 | ShallowSubmodules bool
179 | SeparateGitDir,
180 | Config string
181 | Ipv4,
182 | Ipv6 bool
183 | Filter string
184 | }
185 |
186 | func (c *Clone) Doc() string {
187 | return `usage: git clone [] --repository= --directory=
188 |
189 | arguments:
190 |
191 | -r, --repository repository to clone
192 | -d, --directory path to directory
193 | -v, --verbose be more verbose
194 | -q, --quiet be more quiet
195 | --progress force progress reporting
196 | -n, --no-checkout don't create a checkout
197 | --bare create a bare repository
198 | --mirror create a mirror repository (implies bare)
199 | -l, --local to clone from a local repository
200 | --no-hardlinks don't use local hardlinks, always copy
201 | -s, --shared setup as shared repository
202 | --recurse-submodules= initialize submodules in the clone
203 | -j, --jobs= number of submodules cloned in parallel
204 | --template= directory from which templates will be used
205 | --reference= reference repository
206 | --reference-if-able= reference repository
207 | --dissociate use --reference only while cloning
208 | -o, --origin= use instead of 'origin' to track upstream
209 | -b, --branch= checkout instead of the remote's HEAD
210 | -u, --upload-pack= path to git-upload-pack on the remote
211 | --depth= create a shallow clone of that depth
212 | --shallow-since=}}
237 |
238 | In this tutorial, we won’t go into detail about the logic of the Clone command because its functionality is pretty straightforward.
239 |
240 | ### Writing the Methods’ Logic
241 |
242 | A specific method will run when a certain condition is met.
243 |
244 | #### **Error method**
245 |
246 | The Error method will run when the user passes an argument or command that is not registered in the docstring. Usually, you'll just print the error message to `stderr` and exit the program. In our example, we'll ignore invalid arguments and force the Run method to run, otherwise we'll print the error message to `stderr` and exit the program:
247 |
248 | {{}}
249 | func (g *Git) Error(err error) {
250 | switch err.(type) {
251 | case *args.InvalidArgumentError:
252 | // Ignore InvalidArgumentError.
253 | g.Run()
254 | default:
255 | log.Fatal(err)
256 | }
257 | }
258 | {{}}
259 |
260 | The `InvalidArgumentError` is within the `args` package, so make sure to add `"github.com/celicoo/docli/v2/args"` to
261 | the import declarations.
262 |
263 | #### **Help method**
264 |
265 | The Help method will run when the user passes the `help` argument. Usually, you'll just print the docstring to `stdout`; that’s what we’ll do in our example:
266 |
267 | {{}}
268 | func (g *Git) Help() {
269 | fmt.Println(g.Doc())
270 | }
271 | {{}}
272 |
273 | #### **Run method**
274 |
275 | The Run method will run when no error is found and an argument other than `help` is called. In our example we'll print the version if the `--version` (or `-v`) command-line argument is passed, otherwise we'll just print "Hello, world!":
276 |
277 | {{}}
278 | func (g *Git) Run() {
279 | if g.Version {
280 | fmt.Println(version)
281 | return
282 | }
283 | fmt.Println("Hello, world!")
284 | }
285 | {{}}
286 |
287 | ### Initializing Docli
288 |
289 | We created a CLI app with one command and one argument. But if you try to execute it, it won’t run. There is one piece missing: initializing Docli.
290 |
291 | {{}}
292 | func Execute() {
293 | var g Git
294 | args := docli.Args()
295 | args.Bind(&g)
296 | }
297 | {{}}
298 |
299 | ### Testing the CLI app
300 |
301 | The very last step is to make sure it’s actually working. To do that, we need to build and run it:
302 |
303 | {{}}
304 | $ go build
305 | $ ./git
306 |
307 | Hello, world!
308 | {{}}
309 |
310 | Unlike other packages, Docli doesn't allow values to be assigned to arguments without using the `=` operator. You need to use the `=` operator, otherwise the internal parser will think you’re passing an argument and, as a result, the `Error` method of the struct that represents the command that you're executing will be called. The `clone` command was added to help you understand this, so go ahead and play with it.
311 |
312 | Congratulations! You’ve completed the tutorial. Thank you for reading, and I hope you enjoyed it.
313 |
314 | If you have any question, please don’t hesitate to [open an issue](https://github.com/celicoo/docli/issues).
315 |
--------------------------------------------------------------------------------
/docs/content/docs/unsupported-features/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Unsupported features
3 | ---
4 |
5 | # Unsupported features
6 |
7 | Right now, Docli doesn't support the following features:
8 |
9 | * Bash autocomplete
10 | * Default values
11 | * Global arguments
12 | * Intelligent suggestions
13 | * Positional arguments
14 |
15 | If you need either one of those features, we recommend you to check out [awesome-go#standard-cli](https://github.com/avelino/awesome-go#standard-cli).
16 |
--------------------------------------------------------------------------------
/docs/content/menu/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | headless: true
3 | ---
4 |
5 | - [Introduction]({{< relref "/" >}})
6 | - [Installation]({{< relref "/docs/installation" >}})
7 | - [Tutorial]({{< relref "/docs/tutorial" >}})
8 | - [Unsupported features]({{< relref "/docs/unsupported-features" >}})
9 | - [Examples](https://github.com/celicoo/docli/tree/main/examples)
10 | - [Feedback]({{< relref "/docs/feedback" >}})
11 | - [License](https://github.com/celicoo/docli/blob/main/LICENSE)
12 |
--------------------------------------------------------------------------------
/docs/layouts/partials/docs/brand.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/docs/layouts/partials/docs/inject/head.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/layouts/partials/docs/inject/menu-after.html:
--------------------------------------------------------------------------------
1 | Star
2 | Watch
3 |
--------------------------------------------------------------------------------
/docs/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 404 Page not found | Docli
14 |
15 |
16 |
17 |
18 |
19 |
20 |
29 |
30 |
34 |
35 |
36 |
37 |
47 |
48 |
49 |
50 |
51 |
162 |
163 |
164 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
--------------------------------------------------------------------------------
/docs/public/docs/index.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Docs on Docli
5 | https://docli.dev/docs/
6 | Recent content in Docs on Docli
7 | Hugo -- gohugo.io
8 | en-us
9 |
10 | Feedback
11 | https://docli.dev/docs/feedback/
12 | Mon, 01 Jan 0001 00:00:00 +0000
13 |
14 | https://docli.dev/docs/feedback/
15 | Feedback # Feel free to send me feedback on Twitter or file an issue. Feature requests and contributions are always welcome.
16 |
17 |
18 |
19 | Installation
20 | https://docli.dev/docs/installation/
21 | Mon, 01 Jan 0001 00:00:00 +0000
22 |
23 | https://docli.dev/docs/installation/
24 | Installation # You can install Docli with a single command using go get, the Go package manager. Type this into your terminal:
25 | $ go get -u github.com/celicoo/docli/v2@latest Don’t have Go installed? Learn how to install Go here.
26 |
27 |
28 |
29 | Tutorial
30 | https://docli.dev/docs/tutorial/
31 | Mon, 01 Jan 0001 00:00:00 +0000
32 |
33 | https://docli.dev/docs/tutorial/
34 | Tutorial # Welcome to the Docli Tutorial! Here you’ll be introduced to the key Docli concepts. If you get stuck at any point in the process, feel free to download a working example of the completed CLI app.
35 | Confirming that Docli is installed # Before starting the tutorial, let’s make sure that you have Docli installed. Go ahead and create a main.go file and paste the following content inside:
36 |
37 |
38 |
39 | Unsupported features
40 | https://docli.dev/docs/unsupported-features/
41 | Mon, 01 Jan 0001 00:00:00 +0000
42 |
43 | https://docli.dev/docs/unsupported-features/
44 | Unsupported features # Right now, Docli doesn’t support the following features:
45 | Bash autocomplete Default values Global arguments Intelligent suggestions Positional arguments If you need either one of those features, we recommend you to check out awesome-go#standard-cli.
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/docs/public/docs/installation/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 | Installation | Docli
17 |
18 |
19 |
20 |
21 |
22 |
23 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
102 |
103 |
Permission is hereby granted, free of charge, to any person obtaining a copy
140 | of this software and associated documentation files (the “Software”), to deal
141 | in the Software without restriction, including without limitation the rights
142 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
143 | copies of the Software, and to permit persons to whom the Software is
144 | furnished to do so, subject to the following conditions:
145 |
The above copyright notice and this permission notice shall be included in all
146 | copies or substantial portions of the Software.
147 |
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
148 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
149 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
150 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153 | SOFTWARE.
195 |
196 |
197 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
--------------------------------------------------------------------------------
/docs/public/en.search-data.min.2e4816fcf335f19843d3e87d03c3ffbb98d6cc8dac625000b49e5493642d1265.json:
--------------------------------------------------------------------------------
1 | [{"id":0,"href":"/docs/feedback/","title":"Feedback","section":"Docs","content":"Feedback # Feel free to send me feedback on Twitter or file an issue. Feature requests and contributions are always welcome.\n"},{"id":1,"href":"/docs/installation/","title":"Installation","section":"Docs","content":"Installation # You can install Docli with a single command using go get, the Go package manager. Type this into your terminal:\n$ go get -u github.com/celicoo/docli/v2@latest Don\u0026rsquo;t have Go installed? Learn how to install Go here.\n"},{"id":2,"href":"/docs/license/","title":"License","section":"Docs","content":"MIT License # Copyright (c) 2018\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u0026ldquo;Software\u0026rdquo;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \u0026ldquo;AS IS\u0026rdquo;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"},{"id":3,"href":"/docs/tutorial/","title":"Tutorial","section":"Docs","content":"Tutorial # Welcome to the Docli Tutorial! Here you\u0026rsquo;ll be introduced to the key Docli concepts. If you get stuck at any point in the process, feel free to download a working example of the completed CLI app.\nConfirming that Docli is installed # Before starting the tutorial, let\u0026rsquo;s make sure that you have Docli installed. Go ahead and create a main.go file and paste the following content inside:\npackage main import ( \u0026#34;github.com/alecthomas/repr\u0026#34; \u0026#34;github.com/celicoo/docli\u0026#34; ) func main() { args := docli.Args() repr.Println(args) } Now build and run it:\n$ go build $ ./main docli.args{ } Note: the output is the Abstract Syntax Structure of the command-line arguments, and it\u0026rsquo;s empty because you didn\u0026rsquo;t pass any arguments. If you run it again passing arguments you should see a different output.\nCreating a new CLI app # Directory structure # If you like Cobra, you\u0026rsquo;ll feel at home with this. While you\u0026rsquo;re welcome to provide your own organization, typically a Docli-based app will follow the following directory structure:\n▾ app/ ▾ cmd/ root.go main.go Go ahead and create the above structure, but instead of app, let\u0026rsquo;s name the root directory to git.\napp/ # This is the root of our app. The main.go file goes into this directory and it\u0026rsquo;s responsible for calling the function that initializes Docli:\npackage main import \u0026#34;\u0026lt;path\u0026gt;/git\u0026#34; func main() { cmd.Execute() } Note: Make sure to replace the \u0026lt;path\u0026gt; placeholder.\ncmd/ # This is where the commands are stored. The root.go is responsible for the logic of the root command and the Execute() function:\npackage cmd const version = \u0026#34;0.0.1\u0026#34; type Git struct {} func (g *Git) Doc() string { return \u0026#34;\u0026#34; } func (g *Git) Run() { } func (g *Git) Help() { } func (g *Git) Error(err error) { } func Execute() { } The Git struct represents the root command in our CLI app and it must implement the docli.command interface.\nWriting the docstring # Like YAML or Python, the docstring is a line-oriented language that uses indentation to define structure. Lines beginning with either spaces or tabs are used to register arguments and commands (commands are explained a little later in the tutorial). These arguments and commands can have letters of any language, numbers, and dashes.\nLet’s go back to the root.go file and replace the Doc() method of our Git struct with:\nfunc (g *Git) Doc() string { return `usage: git \u0026lt;command\u0026gt; commands: c, clone clone a repository into a new directory arguments: v, --version print version Use \u0026#34;git \u0026lt;command\u0026gt; help\u0026#34; for more information about the \u0026lt;command\u0026gt;.` } By convention, dashes are used in front of arguments, but not commands. You can use this convention with Docli, but it\u0026rsquo;s not necessary.\nAccessing command-line argument values # Now that we’ve registered the arguments and commands in the docstring, we’ll need to define them as fields in the Git struct, so we can access their values. Fields that represent arguments will be primitive types and those that represent commands will be user-defined types that implement the docli.command interface, just like the root command does.\nRegardless of how many aliases your arguments or commands have , you\u0026rsquo;ll only need to (and only should) define one field in the struct. We suggest using the longer identifier, but you can use whichever you’d like.\nIn our example, we have one command and one argument, and each has two identifiers. Let’s add these to our Git struct:\ntype Git struct { Clone Clone Version bool } For every command, you’ll need to create a file to hold the type that represents the command. In our example, the Clone field represents the clone command, so we need to create a file that holds this type. Let\u0026rsquo;s go ahead and create the clone.go file inside the cmd directory and paste the following code inside:\npackage cmd import ( \u0026#34;fmt\u0026#34; \u0026#34;log\u0026#34; \u0026#34;github.com/alecthomas/repr\u0026#34; ) type Clone struct { Repository, Directory string Verbose, Quiet, Progress, NoCheckout, Bare, Mirror, Local, NoHardlinks, Shared bool RecurseSubmodules string Jobs int Template, Reference, ReferenceIfAble string Dissociate bool Origin, Branch, UploadPack string Depth int ShallowSince, ShallowExclude string SingleBranch, NoTags, ShallowSubmodules bool SeparateGitDir, Config string Ipv4, Ipv6 bool Filter string } func (c *Clone) Doc() string { return `usage: git clone [\u0026lt;arguments\u0026gt;] --repository=\u0026lt;url\u0026gt; --directory=\u0026lt;directory\u0026gt; arguments: -r, --repository repository to clone -d, --directory path to directory -v, --verbose be more verbose -q, --quiet be more quiet --progress force progress reporting -n, --no-checkout don\u0026#39;t create a checkout --bare create a bare repository --mirror create a mirror repository (implies bare) -l, --local to clone from a local repository --no-hardlinks don\u0026#39;t use local hardlinks, always copy -s, --shared setup as shared repository --recurse-submodules=\u0026lt;pathspec\u0026gt; initialize submodules in the clone -j, --jobs=\u0026lt;n\u0026gt; number of submodules cloned in parallel --template=\u0026lt;template-directory\u0026gt; directory from which templates will be used --reference=\u0026lt;repo\u0026gt; reference repository --reference-if-able=\u0026lt;repo\u0026gt; reference repository --dissociate use --reference only while cloning -o, --origin=\u0026lt;name\u0026gt; use \u0026lt;name\u0026gt; instead of \u0026#39;origin\u0026#39; to track upstream -b, --branch=\u0026lt;branch\u0026gt; checkout \u0026lt;branch\u0026gt; instead of the remote\u0026#39;s HEAD -u, --upload-pack=\u0026lt;path\u0026gt; path to git-upload-pack on the remote --depth=\u0026lt;depth\u0026gt; create a shallow clone of that depth --shallow-since=\u0026lt;time\u0026gt; create a shallow clone since a specific time --shallow-exclude=\u0026lt;revision\u0026gt; deepen history of shallow clone, excluding rev --single-branch clone only one branch, HEAD or --branch --no-tags don\u0026#39;t clone any tags, and make later fetches not to follow them --shallow-submodules any cloned submodules will be shallow --separate-git-dir=\u0026lt;gitdir\u0026gt; separate git dir from working tree -c, --config=\u0026lt;key=value\u0026gt; set config inside the new repository -4, --ipv4 use IPv4 addresses only -6, --ipv6 use IPv6 addresses only --filter=\u0026lt;args\u0026gt; object filtering ` } func (c *Clone) Run() { repr.Println(c) } func (c *Clone) Help() { fmt.Println(c.Doc()) } func (c *Clone) Error(err error) { log.Fatal(err) } In this tutorial, we won’t go into detail about the logic of the Clone command because its functionality is pretty straightforward.\nWriting the Methods’ Logic # A specific method will run when a certain condition is met.\nError method # The Error method will run when the user passes an argument or command that is not registered in the docstring. Usually, you\u0026rsquo;ll just print the error message to stderr and exit the program. In our example, we\u0026rsquo;ll ignore invalid arguments and force the Run method to run, otherwise we\u0026rsquo;ll print the error message to stderr and exit the program:\nfunc (g *Git) Error(err error) { switch err.(type) { case *args.InvalidArgumentError: // Ignore InvalidArgumentError. \tg.Run() default: log.Fatal(err) } } The InvalidArgumentError is within the args package, so make sure to add \u0026quot;github.com/celicoo/docli/args\u0026quot; to the import declarations.\nHelp method # The Help method will run when the user passes the help argument. Usually, you\u0026rsquo;ll just print the docstring to stdout; that’s what we’ll do in our example:\nfunc (g *Git) Help() { fmt.Println(g.Doc()) } Run method # The Run method will run when no error is found and an argument other than help is called. In our example we\u0026rsquo;ll print the version if the --version (or -v) command-line argument is passed, otherwise we\u0026rsquo;ll just print \u0026ldquo;Hello, world!\u0026quot;:\nfunc (g *Git) Run() { if g.Version { fmt.Println(version) return } fmt.Println(\u0026#34;Hello, world!\u0026#34;) } Initializing Docli # We created a CLI app with one command and one argument. But if you try to execute it, it won’t run. There is one piece missing: initializing Docli.\nfunc Execute() { var g Git args := docli.Args() args.Bind(\u0026amp;g) } Testing the CLI app # The very last step is to make sure it’s actually working. To do that, we need to build and run it:\n$ go build $ ./git Hello, world! Unlike other packages, Docli doesn\u0026rsquo;t allow values to be assigned to arguments without using the = operator. You need to use the = operator, otherwise the internal parser will think you’re passing an argument and, as a result, the Error method of the struct that represents the command that you\u0026rsquo;re executing will be called. The clone command was added to help you understand this, so go ahead and play with it.\nCongratulations! You’ve completed the tutorial. Thank you for reading, and I hope you enjoyed it.\nIf you have any question, please don’t hesitate to open an issue.\n"},{"id":4,"href":"/docs/unsupported-features/","title":"Unsupported features","section":"Docs","content":"Unsupported features # Right now, Docli doesn\u0026rsquo;t support the following features:\n Bash autocomplete Default values Global arguments Intelligent suggestions Positional arguments If you absolutely need either one of those features, we recommend these alternative libraries.\n"}]
--------------------------------------------------------------------------------
/docs/public/en.search-data.min.b7c721dd1bec1696af0abc4157baf0d185c534cdcc71d9a1ce52329b7ec6da43.json:
--------------------------------------------------------------------------------
1 | [{"id":0,"href":"/docs/feedback/","title":"Feedback","section":"Docs","content":"Feedback # Feel free to send me feedback on Twitter or file an issue. Feature requests and contributions are always welcome.\n"},{"id":1,"href":"/docs/installation/","title":"Installation","section":"Docs","content":"Installation # You can install Docli with a single command using go get, the Go package manager. Type this into your terminal:\n$ go get -u github.com/celicoo/docli/v2@latest Don\u0026rsquo;t have Go installed? Learn how to install Go here.\n"},{"id":2,"href":"/docs/tutorial/","title":"Tutorial","section":"Docs","content":"Tutorial # Welcome to the Docli Tutorial! Here you\u0026rsquo;ll be introduced to the key Docli concepts. If you get stuck at any point in the process, feel free to download a working example of the completed CLI app.\nConfirming that Docli is installed # Before starting the tutorial, let\u0026rsquo;s make sure that you have Docli installed. Go ahead and create a main.go file and paste the following content inside:\npackage main import ( \u0026#34;github.com/alecthomas/repr\u0026#34; \u0026#34;github.com/celicoo/docli/v2\u0026#34; ) func main() { args := docli.Args() repr.Println(args) } Now build and run it:\n$ go build $ ./main docli.args{ } Note: the output is the Abstract Syntax Structure of the command-line arguments, and it\u0026rsquo;s empty because you didn\u0026rsquo;t pass any arguments. If you run it again passing arguments you should see a different output.\nCreating a new CLI app # Directory structure # If you like Cobra, you\u0026rsquo;ll feel at home with this. While you\u0026rsquo;re welcome to provide your own organization, typically a Docli-based app will follow the following directory structure:\n▾ app/ ▾ cmd/ root.go main.go Go ahead and create the above structure, but instead of app, let\u0026rsquo;s name the root directory to git.\napp/ # This is the root of our app. The main.go file goes into this directory and it\u0026rsquo;s responsible for calling the function that initializes Docli:\npackage main import \u0026#34;\u0026lt;path\u0026gt;/git\u0026#34; func main() { cmd.Execute() } Note: Make sure to replace the \u0026lt;path\u0026gt; placeholder.\ncmd/ # This is where the commands are stored. The root.go is responsible for the logic of the root command and the Execute() function:\npackage cmd const version = \u0026#34;0.0.1\u0026#34; type Git struct {} func (g *Git) Doc() string { return \u0026#34;\u0026#34; } func (g *Git) Run() { } func (g *Git) Help() { } func (g *Git) Error(err error) { } func Execute() { } The Git struct represents the root command in our CLI app and it must implement the docli.command interface.\nWriting the docstring # Like YAML or Python, the docstring is a line-oriented language that uses indentation to define structure. Lines beginning with either spaces or tabs are used to register arguments and commands (commands are explained a little later in the tutorial). These arguments and commands can have letters of any language, numbers, and dashes.\nLet’s go back to the root.go file and replace the Doc() method of our Git struct with:\nfunc (g *Git) Doc() string { return `usage: git \u0026lt;command\u0026gt; commands: c, clone clone a repository into a new directory arguments: v, --version print version Use \u0026#34;git \u0026lt;command\u0026gt; help\u0026#34; for more information about the \u0026lt;command\u0026gt;.` } By convention, dashes are used in front of arguments, but not commands. You can use this convention with Docli, but it\u0026rsquo;s not necessary.\nAccessing command-line argument values # Now that we’ve registered the arguments and commands in the docstring, we’ll need to define them as fields in the Git struct, so we can access their values. Fields that represent arguments will be primitive types and those that represent commands will be user-defined types that implement the docli.command interface, just like the root command does.\nRegardless of how many aliases your arguments or commands have , you\u0026rsquo;ll only need to (and only should) define one field in the struct. We suggest using the longer identifier, but you can use whichever you’d like.\nIn our example, we have one command and one argument, and each has two identifiers. Let’s add these to our Git struct:\ntype Git struct { Clone Clone Version bool } For every command, you’ll need to create a file to hold the type that represents the command. In our example, the Clone field represents the clone command, so we need to create a file that holds this type. Let\u0026rsquo;s go ahead and create the clone.go file inside the cmd directory and paste the following code inside:\npackage cmd import ( \u0026#34;fmt\u0026#34; \u0026#34;log\u0026#34; \u0026#34;github.com/alecthomas/repr\u0026#34; ) type Clone struct { Repository, Directory string Verbose, Quiet, Progress, NoCheckout, Bare, Mirror, Local, NoHardlinks, Shared bool RecurseSubmodules string Jobs int Template, Reference, ReferenceIfAble string Dissociate bool Origin, Branch, UploadPack string Depth int ShallowSince, ShallowExclude string SingleBranch, NoTags, ShallowSubmodules bool SeparateGitDir, Config string Ipv4, Ipv6 bool Filter string } func (c *Clone) Doc() string { return `usage: git clone [\u0026lt;arguments\u0026gt;] --repository=\u0026lt;url\u0026gt; --directory=\u0026lt;directory\u0026gt; arguments: -r, --repository repository to clone -d, --directory path to directory -v, --verbose be more verbose -q, --quiet be more quiet --progress force progress reporting -n, --no-checkout don\u0026#39;t create a checkout --bare create a bare repository --mirror create a mirror repository (implies bare) -l, --local to clone from a local repository --no-hardlinks don\u0026#39;t use local hardlinks, always copy -s, --shared setup as shared repository --recurse-submodules=\u0026lt;pathspec\u0026gt; initialize submodules in the clone -j, --jobs=\u0026lt;n\u0026gt; number of submodules cloned in parallel --template=\u0026lt;template-directory\u0026gt; directory from which templates will be used --reference=\u0026lt;repo\u0026gt; reference repository --reference-if-able=\u0026lt;repo\u0026gt; reference repository --dissociate use --reference only while cloning -o, --origin=\u0026lt;name\u0026gt; use \u0026lt;name\u0026gt; instead of \u0026#39;origin\u0026#39; to track upstream -b, --branch=\u0026lt;branch\u0026gt; checkout \u0026lt;branch\u0026gt; instead of the remote\u0026#39;s HEAD -u, --upload-pack=\u0026lt;path\u0026gt; path to git-upload-pack on the remote --depth=\u0026lt;depth\u0026gt; create a shallow clone of that depth --shallow-since=\u0026lt;time\u0026gt; create a shallow clone since a specific time --shallow-exclude=\u0026lt;revision\u0026gt; deepen history of shallow clone, excluding rev --single-branch clone only one branch, HEAD or --branch --no-tags don\u0026#39;t clone any tags, and make later fetches not to follow them --shallow-submodules any cloned submodules will be shallow --separate-git-dir=\u0026lt;gitdir\u0026gt; separate git dir from working tree -c, --config=\u0026lt;key=value\u0026gt; set config inside the new repository -4, --ipv4 use IPv4 addresses only -6, --ipv6 use IPv6 addresses only --filter=\u0026lt;args\u0026gt; object filtering ` } func (c *Clone) Run() { repr.Println(c) } func (c *Clone) Help() { fmt.Println(c.Doc()) } func (c *Clone) Error(err error) { log.Fatal(err) } In this tutorial, we won’t go into detail about the logic of the Clone command because its functionality is pretty straightforward.\nWriting the Methods’ Logic # A specific method will run when a certain condition is met.\nError method # The Error method will run when the user passes an argument or command that is not registered in the docstring. Usually, you\u0026rsquo;ll just print the error message to stderr and exit the program. In our example, we\u0026rsquo;ll ignore invalid arguments and force the Run method to run, otherwise we\u0026rsquo;ll print the error message to stderr and exit the program:\nfunc (g *Git) Error(err error) { switch err.(type) { case *args.InvalidArgumentError: // Ignore InvalidArgumentError. \tg.Run() default: log.Fatal(err) } } The InvalidArgumentError is within the args package, so make sure to add \u0026quot;github.com/celicoo/docli/v2/args\u0026quot; to the import declarations.\nHelp method # The Help method will run when the user passes the help argument. Usually, you\u0026rsquo;ll just print the docstring to stdout; that’s what we’ll do in our example:\nfunc (g *Git) Help() { fmt.Println(g.Doc()) } Run method # The Run method will run when no error is found and an argument other than help is called. In our example we\u0026rsquo;ll print the version if the --version (or -v) command-line argument is passed, otherwise we\u0026rsquo;ll just print \u0026ldquo;Hello, world!\u0026quot;:\nfunc (g *Git) Run() { if g.Version { fmt.Println(version) return } fmt.Println(\u0026#34;Hello, world!\u0026#34;) } Initializing Docli # We created a CLI app with one command and one argument. But if you try to execute it, it won’t run. There is one piece missing: initializing Docli.\nfunc Execute() { var g Git args := docli.Args() args.Bind(\u0026amp;g) } Testing the CLI app # The very last step is to make sure it’s actually working. To do that, we need to build and run it:\n$ go build $ ./git Hello, world! Unlike other packages, Docli doesn\u0026rsquo;t allow values to be assigned to arguments without using the = operator. You need to use the = operator, otherwise the internal parser will think you’re passing an argument and, as a result, the Error method of the struct that represents the command that you\u0026rsquo;re executing will be called. The clone command was added to help you understand this, so go ahead and play with it.\nCongratulations! You’ve completed the tutorial. Thank you for reading, and I hope you enjoyed it.\nIf you have any question, please don’t hesitate to open an issue.\n"},{"id":3,"href":"/docs/unsupported-features/","title":"Unsupported features","section":"Docs","content":"Unsupported features # Right now, Docli doesn\u0026rsquo;t support the following features:\n Bash autocomplete Default values Global arguments Intelligent suggestions Positional arguments If you need either one of those features, we recommend you to check out awesome-go#standard-cli.\n"}]
--------------------------------------------------------------------------------
/docs/public/en.search-data.min.e590e8c46a909cea153ae2ea57829c489ba98d785de4512d3fc3650c9ee2e0ad.json:
--------------------------------------------------------------------------------
1 | [{"id":0,"href":"/docs/feedback/","title":"Feedback","section":"Docs","content":"Feedback # Feel free to send me feedback on Twitter or file an issue. Feature requests and contributions are always welcome.\n"},{"id":1,"href":"/docs/installation/","title":"Installation","section":"Docs","content":"Installation # You can install Docli with a single command using go get, the Go package manager. Type this into your terminal:\n$ go get -u github.com/celicoo/docli/v2@latest Don\u0026rsquo;t have Go installed? Learn how to install Go here.\n"},{"id":2,"href":"/docs/tutorial/","title":"Tutorial","section":"Docs","content":"Tutorial # Welcome to the Docli Tutorial! Here you\u0026rsquo;ll be introduced to the key Docli concepts. If you get stuck at any point in the process, feel free to download a working example of the completed CLI app.\nConfirming that Docli is installed # Before starting the tutorial, let\u0026rsquo;s make sure that you have Docli installed. Go ahead and create a main.go file and paste the following content inside:\npackage main import ( \u0026#34;github.com/alecthomas/repr\u0026#34; \u0026#34;github.com/celicoo/docli\u0026#34; ) func main() { args := docli.Args() repr.Println(args) } Now build and run it:\n$ go build $ ./main docli.args{ } Note: the output is the Abstract Syntax Structure of the command-line arguments, and it\u0026rsquo;s empty because you didn\u0026rsquo;t pass any arguments. If you run it again passing arguments you should see a different output.\nCreating a new CLI app # Directory structure # If you like Cobra, you\u0026rsquo;ll feel at home with this. While you\u0026rsquo;re welcome to provide your own organization, typically a Docli-based app will follow the following directory structure:\n▾ app/ ▾ cmd/ root.go main.go Go ahead and create the above structure, but instead of app, let\u0026rsquo;s name the root directory to git.\napp/ # This is the root of our app. The main.go file goes into this directory and it\u0026rsquo;s responsible for calling the function that initializes Docli:\npackage main import \u0026#34;\u0026lt;path\u0026gt;/git\u0026#34; func main() { cmd.Execute() } Note: Make sure to replace the \u0026lt;path\u0026gt; placeholder.\ncmd/ # This is where the commands are stored. The root.go is responsible for the logic of the root command and the Execute() function:\npackage cmd const version = \u0026#34;0.0.1\u0026#34; type Git struct {} func (g *Git) Doc() string { return \u0026#34;\u0026#34; } func (g *Git) Run() { } func (g *Git) Help() { } func (g *Git) Error(err error) { } func Execute() { } The Git struct represents the root command in our CLI app and it must implement the docli.command interface.\nWriting the docstring # Like YAML or Python, the docstring is a line-oriented language that uses indentation to define structure. Lines beginning with either spaces or tabs are used to register arguments and commands (commands are explained a little later in the tutorial). These arguments and commands can have letters of any language, numbers, and dashes.\nLet’s go back to the root.go file and replace the Doc() method of our Git struct with:\nfunc (g *Git) Doc() string { return `usage: git \u0026lt;command\u0026gt; commands: c, clone clone a repository into a new directory arguments: v, --version print version Use \u0026#34;git \u0026lt;command\u0026gt; help\u0026#34; for more information about the \u0026lt;command\u0026gt;.` } By convention, dashes are used in front of arguments, but not commands. You can use this convention with Docli, but it\u0026rsquo;s not necessary.\nAccessing command-line argument values # Now that we’ve registered the arguments and commands in the docstring, we’ll need to define them as fields in the Git struct, so we can access their values. Fields that represent arguments will be primitive types and those that represent commands will be user-defined types that implement the docli.command interface, just like the root command does.\nRegardless of how many aliases your arguments or commands have , you\u0026rsquo;ll only need to (and only should) define one field in the struct. We suggest using the longer identifier, but you can use whichever you’d like.\nIn our example, we have one command and one argument, and each has two identifiers. Let’s add these to our Git struct:\ntype Git struct { Clone Clone Version bool } For every command, you’ll need to create a file to hold the type that represents the command. In our example, the Clone field represents the clone command, so we need to create a file that holds this type. Let\u0026rsquo;s go ahead and create the clone.go file inside the cmd directory and paste the following code inside:\npackage cmd import ( \u0026#34;fmt\u0026#34; \u0026#34;log\u0026#34; \u0026#34;github.com/alecthomas/repr\u0026#34; ) type Clone struct { Repository, Directory string Verbose, Quiet, Progress, NoCheckout, Bare, Mirror, Local, NoHardlinks, Shared bool RecurseSubmodules string Jobs int Template, Reference, ReferenceIfAble string Dissociate bool Origin, Branch, UploadPack string Depth int ShallowSince, ShallowExclude string SingleBranch, NoTags, ShallowSubmodules bool SeparateGitDir, Config string Ipv4, Ipv6 bool Filter string } func (c *Clone) Doc() string { return `usage: git clone [\u0026lt;arguments\u0026gt;] --repository=\u0026lt;url\u0026gt; --directory=\u0026lt;directory\u0026gt; arguments: -r, --repository repository to clone -d, --directory path to directory -v, --verbose be more verbose -q, --quiet be more quiet --progress force progress reporting -n, --no-checkout don\u0026#39;t create a checkout --bare create a bare repository --mirror create a mirror repository (implies bare) -l, --local to clone from a local repository --no-hardlinks don\u0026#39;t use local hardlinks, always copy -s, --shared setup as shared repository --recurse-submodules=\u0026lt;pathspec\u0026gt; initialize submodules in the clone -j, --jobs=\u0026lt;n\u0026gt; number of submodules cloned in parallel --template=\u0026lt;template-directory\u0026gt; directory from which templates will be used --reference=\u0026lt;repo\u0026gt; reference repository --reference-if-able=\u0026lt;repo\u0026gt; reference repository --dissociate use --reference only while cloning -o, --origin=\u0026lt;name\u0026gt; use \u0026lt;name\u0026gt; instead of \u0026#39;origin\u0026#39; to track upstream -b, --branch=\u0026lt;branch\u0026gt; checkout \u0026lt;branch\u0026gt; instead of the remote\u0026#39;s HEAD -u, --upload-pack=\u0026lt;path\u0026gt; path to git-upload-pack on the remote --depth=\u0026lt;depth\u0026gt; create a shallow clone of that depth --shallow-since=\u0026lt;time\u0026gt; create a shallow clone since a specific time --shallow-exclude=\u0026lt;revision\u0026gt; deepen history of shallow clone, excluding rev --single-branch clone only one branch, HEAD or --branch --no-tags don\u0026#39;t clone any tags, and make later fetches not to follow them --shallow-submodules any cloned submodules will be shallow --separate-git-dir=\u0026lt;gitdir\u0026gt; separate git dir from working tree -c, --config=\u0026lt;key=value\u0026gt; set config inside the new repository -4, --ipv4 use IPv4 addresses only -6, --ipv6 use IPv6 addresses only --filter=\u0026lt;args\u0026gt; object filtering ` } func (c *Clone) Run() { repr.Println(c) } func (c *Clone) Help() { fmt.Println(c.Doc()) } func (c *Clone) Error(err error) { log.Fatal(err) } In this tutorial, we won’t go into detail about the logic of the Clone command because its functionality is pretty straightforward.\nWriting the Methods’ Logic # A specific method will run when a certain condition is met.\nError method # The Error method will run when the user passes an argument or command that is not registered in the docstring. Usually, you\u0026rsquo;ll just print the error message to stderr and exit the program. In our example, we\u0026rsquo;ll ignore invalid arguments and force the Run method to run, otherwise we\u0026rsquo;ll print the error message to stderr and exit the program:\nfunc (g *Git) Error(err error) { switch err.(type) { case *args.InvalidArgumentError: // Ignore InvalidArgumentError. \tg.Run() default: log.Fatal(err) } } The InvalidArgumentError is within the args package, so make sure to add \u0026quot;github.com/celicoo/docli/args\u0026quot; to the import declarations.\nHelp method # The Help method will run when the user passes the help argument. Usually, you\u0026rsquo;ll just print the docstring to stdout; that’s what we’ll do in our example:\nfunc (g *Git) Help() { fmt.Println(g.Doc()) } Run method # The Run method will run when no error is found and an argument other than help is called. In our example we\u0026rsquo;ll print the version if the --version (or -v) command-line argument is passed, otherwise we\u0026rsquo;ll just print \u0026ldquo;Hello, world!\u0026quot;:\nfunc (g *Git) Run() { if g.Version { fmt.Println(version) return } fmt.Println(\u0026#34;Hello, world!\u0026#34;) } Initializing Docli # We created a CLI app with one command and one argument. But if you try to execute it, it won’t run. There is one piece missing: initializing Docli.\nfunc Execute() { var g Git args := docli.Args() args.Bind(\u0026amp;g) } Testing the CLI app # The very last step is to make sure it’s actually working. To do that, we need to build and run it:\n$ go build $ ./git Hello, world! Unlike other packages, Docli doesn\u0026rsquo;t allow values to be assigned to arguments without using the = operator. You need to use the = operator, otherwise the internal parser will think you’re passing an argument and, as a result, the Error method of the struct that represents the command that you\u0026rsquo;re executing will be called. The clone command was added to help you understand this, so go ahead and play with it.\nCongratulations! You’ve completed the tutorial. Thank you for reading, and I hope you enjoyed it.\nIf you have any question, please don’t hesitate to open an issue.\n"},{"id":3,"href":"/docs/unsupported-features/","title":"Unsupported features","section":"Docs","content":"Unsupported features # Right now, Docli doesn\u0026rsquo;t support the following features:\n Bash autocomplete Default values Global arguments Intelligent suggestions Positional arguments If you absolutely need either one of those features, we recommend these alternative libraries.\n"}]
--------------------------------------------------------------------------------
/docs/public/en.search-data.min.eede715b4a6d62ae010148ceeaeb809fca5a0b0d743a280dd9c411fecf86d5dd.json:
--------------------------------------------------------------------------------
1 | [{"id":0,"href":"/docs/feedback/","title":"Feedback","section":"Docs","content":"Feedback # Feel free to send me feedback on Twitter or file an issue. Feature requests and contributions are always welcome.\n"},{"id":1,"href":"/docs/installation/","title":"Installation","section":"Docs","content":"Installation # You can install Docli with a single command using go get, the Go package manager. Type this into your terminal:\n$ go get -u github.com/celicoo/docli/v2@latest Don\u0026rsquo;t have Go installed? Learn how to install Go here.\n"},{"id":2,"href":"/docs/tutorial/","title":"Tutorial","section":"Docs","content":"Tutorial # Welcome to the Docli Tutorial! Here you\u0026rsquo;ll be introduced to the key Docli concepts. If you get stuck at any point in the process, feel free to download a working example of the completed CLI app.\nConfirming that Docli is installed # Before starting the tutorial, let\u0026rsquo;s make sure that you have Docli installed. Go ahead and create a main.go file and paste the following content inside:\npackage main import ( \u0026#34;github.com/alecthomas/repr\u0026#34; \u0026#34;github.com/celicoo/docli/v2\u0026#34; ) func main() { args := docli.Args() repr.Println(args) } Now build and run it:\n$ go build $ ./main docli.args{ } Note: the output is the Abstract Syntax Structure of the command-line arguments, and it\u0026rsquo;s empty because you didn\u0026rsquo;t pass any arguments. If you run it again passing arguments you should see a different output.\nCreating a new CLI app # Directory structure # If you like Cobra, you\u0026rsquo;ll feel at home with this. While you\u0026rsquo;re welcome to provide your own organization, typically a Docli-based app will follow the following directory structure:\n▾ app/ ▾ cmd/ root.go main.go Go ahead and create the above structure, but instead of app, let\u0026rsquo;s name the root directory to git.\napp/ # This is the root of our app. The main.go file goes into this directory and it\u0026rsquo;s responsible for calling the function that initializes Docli:\npackage main import \u0026#34;\u0026lt;path\u0026gt;/git\u0026#34; func main() { cmd.Execute() } Note: Make sure to replace the \u0026lt;path\u0026gt; placeholder.\ncmd/ # This is where the commands are stored. The root.go is responsible for the logic of the root command and the Execute() function:\npackage cmd const version = \u0026#34;0.0.1\u0026#34; type Git struct {} func (g *Git) Doc() string { return \u0026#34;\u0026#34; } func (g *Git) Run() { } func (g *Git) Help() { } func (g *Git) Error(err error) { } func Execute() { } The Git struct represents the root command in our CLI app and it must implement the docli.command interface.\nWriting the docstring # Like YAML or Python, the docstring is a line-oriented language that uses indentation to define structure. Lines beginning with either spaces or tabs are used to register arguments and commands (commands are explained a little later in the tutorial). These arguments and commands can have letters of any language, numbers, and dashes.\nLet’s go back to the root.go file and replace the Doc() method of our Git struct with:\nfunc (g *Git) Doc() string { return `usage: git \u0026lt;command\u0026gt; commands: c, clone clone a repository into a new directory arguments: v, --version print version Use \u0026#34;git \u0026lt;command\u0026gt; help\u0026#34; for more information about the \u0026lt;command\u0026gt;.` } By convention, dashes are used in front of arguments, but not commands. You can use this convention with Docli, but it\u0026rsquo;s not necessary.\nAccessing command-line argument values # Now that we’ve registered the arguments and commands in the docstring, we’ll need to define them as fields in the Git struct, so we can access their values. Fields that represent arguments will be primitive types and those that represent commands will be user-defined types that implement the docli.command interface, just like the root command does.\nRegardless of how many aliases your arguments or commands have , you\u0026rsquo;ll only need to (and only should) define one field in the struct. We suggest using the longer identifier, but you can use whichever you’d like.\nIn our example, we have one command and one argument, and each has two identifiers. Let’s add these to our Git struct:\ntype Git struct { Clone Clone Version bool } For every command, you’ll need to create a file to hold the type that represents the command. In our example, the Clone field represents the clone command, so we need to create a file that holds this type. Let\u0026rsquo;s go ahead and create the clone.go file inside the cmd directory and paste the following code inside:\npackage cmd import ( \u0026#34;fmt\u0026#34; \u0026#34;log\u0026#34; \u0026#34;github.com/alecthomas/repr\u0026#34; ) type Clone struct { Repository, Directory string Verbose, Quiet, Progress, NoCheckout, Bare, Mirror, Local, NoHardlinks, Shared bool RecurseSubmodules string Jobs int Template, Reference, ReferenceIfAble string Dissociate bool Origin, Branch, UploadPack string Depth int ShallowSince, ShallowExclude string SingleBranch, NoTags, ShallowSubmodules bool SeparateGitDir, Config string Ipv4, Ipv6 bool Filter string } func (c *Clone) Doc() string { return `usage: git clone [\u0026lt;arguments\u0026gt;] --repository=\u0026lt;url\u0026gt; --directory=\u0026lt;directory\u0026gt; arguments: -r, --repository repository to clone -d, --directory path to directory -v, --verbose be more verbose -q, --quiet be more quiet --progress force progress reporting -n, --no-checkout don\u0026#39;t create a checkout --bare create a bare repository --mirror create a mirror repository (implies bare) -l, --local to clone from a local repository --no-hardlinks don\u0026#39;t use local hardlinks, always copy -s, --shared setup as shared repository --recurse-submodules=\u0026lt;pathspec\u0026gt; initialize submodules in the clone -j, --jobs=\u0026lt;n\u0026gt; number of submodules cloned in parallel --template=\u0026lt;template-directory\u0026gt; directory from which templates will be used --reference=\u0026lt;repo\u0026gt; reference repository --reference-if-able=\u0026lt;repo\u0026gt; reference repository --dissociate use --reference only while cloning -o, --origin=\u0026lt;name\u0026gt; use \u0026lt;name\u0026gt; instead of \u0026#39;origin\u0026#39; to track upstream -b, --branch=\u0026lt;branch\u0026gt; checkout \u0026lt;branch\u0026gt; instead of the remote\u0026#39;s HEAD -u, --upload-pack=\u0026lt;path\u0026gt; path to git-upload-pack on the remote --depth=\u0026lt;depth\u0026gt; create a shallow clone of that depth --shallow-since=\u0026lt;time\u0026gt; create a shallow clone since a specific time --shallow-exclude=\u0026lt;revision\u0026gt; deepen history of shallow clone, excluding rev --single-branch clone only one branch, HEAD or --branch --no-tags don\u0026#39;t clone any tags, and make later fetches not to follow them --shallow-submodules any cloned submodules will be shallow --separate-git-dir=\u0026lt;gitdir\u0026gt; separate git dir from working tree -c, --config=\u0026lt;key=value\u0026gt; set config inside the new repository -4, --ipv4 use IPv4 addresses only -6, --ipv6 use IPv6 addresses only --filter=\u0026lt;args\u0026gt; object filtering ` } func (c *Clone) Run() { repr.Println(c) } func (c *Clone) Help() { fmt.Println(c.Doc()) } func (c *Clone) Error(err error) { log.Fatal(err) } In this tutorial, we won’t go into detail about the logic of the Clone command because its functionality is pretty straightforward.\nWriting the Methods’ Logic # A specific method will run when a certain condition is met.\nError method # The Error method will run when the user passes an argument or command that is not registered in the docstring. Usually, you\u0026rsquo;ll just print the error message to stderr and exit the program. In our example, we\u0026rsquo;ll ignore invalid arguments and force the Run method to run, otherwise we\u0026rsquo;ll print the error message to stderr and exit the program:\nfunc (g *Git) Error(err error) { switch err.(type) { case *args.InvalidArgumentError: // Ignore InvalidArgumentError. \tg.Run() default: log.Fatal(err) } } The InvalidArgumentError is within the args package, so make sure to add \u0026quot;github.com/celicoo/docli/v2/args\u0026quot; to the import declarations.\nHelp method # The Help method will run when the user passes the help argument. Usually, you\u0026rsquo;ll just print the docstring to stdout; that’s what we’ll do in our example:\nfunc (g *Git) Help() { fmt.Println(g.Doc()) } Run method # The Run method will run when no error is found and an argument other than help is called. In our example we\u0026rsquo;ll print the version if the --version (or -v) command-line argument is passed, otherwise we\u0026rsquo;ll just print \u0026ldquo;Hello, world!\u0026quot;:\nfunc (g *Git) Run() { if g.Version { fmt.Println(version) return } fmt.Println(\u0026#34;Hello, world!\u0026#34;) } Initializing Docli # We created a CLI app with one command and one argument. But if you try to execute it, it won’t run. There is one piece missing: initializing Docli.\nfunc Execute() { var g Git args := docli.Args() args.Bind(\u0026amp;g) } Testing the CLI app # The very last step is to make sure it’s actually working. To do that, we need to build and run it:\n$ go build $ ./git Hello, world! Unlike other packages, Docli doesn\u0026rsquo;t allow values to be assigned to arguments without using the = operator. You need to use the = operator, otherwise the internal parser will think you’re passing an argument and, as a result, the Error method of the struct that represents the command that you\u0026rsquo;re executing will be called. The clone command was added to help you understand this, so go ahead and play with it.\nCongratulations! You’ve completed the tutorial. Thank you for reading, and I hope you enjoyed it.\nIf you have any question, please don’t hesitate to open an issue.\n"},{"id":3,"href":"/docs/unsupported-features/","title":"Unsupported features","section":"Docs","content":"Unsupported features # Right now, Docli doesn\u0026rsquo;t support the following features:\n Bash autocomplete Default values Global arguments Intelligent suggestions Positional arguments If you absolutely need either one of those features, we recommend these alternative libraries.\n"}]
--------------------------------------------------------------------------------
/docs/public/en.search.min.055211035e76540870f517153dc4d92a1bb55b5d44ef3c659de97821b47f221e.js:
--------------------------------------------------------------------------------
1 | 'use strict';(function(){const g='/en.search-data.min.e590e8c46a909cea153ae2ea57829c489ba98d785de4512d3fc3650c9ee2e0ad.json',h=Object.assign({cache:!0},{doc:{id:'id',field:['title','content'],store:['title','href','section']}}),a=document.querySelector('#book-search-input'),b=document.querySelector('#book-search-results');if(!a)return;a.addEventListener('focus',c),a.addEventListener('keyup',d),document.addEventListener('keypress',e);function e(b){if(a===document.activeElement)return;const c=String.fromCharCode(b.charCode);if(!f(c))return;a.focus(),b.preventDefault()}function f(b){const c=a.getAttribute('data-hotkeys')||'';return c.indexOf(b)>=0}function c(){a.removeEventListener('focus',c),a.required=!0,fetch(g).then(a=>a.json()).then(a=>{window.bookSearchIndex=FlexSearch.create('balance',h),window.bookSearchIndex.add(a)}).then(()=>a.required=!1).then(d)}function d(){while(b.firstChild)b.removeChild(b.firstChild);if(!a.value)return;const c=window.bookSearchIndex.search(a.value,10);c.forEach(function(a){const c=i('
Docli is a declarative language for describing command-line interfaces in Go programs. It cuts down the boilerplate to the bare minimum so you’re free to move on to the actual reason you’re making the app in the first place.