man-0.3.0/.github/CODE_OF_CONDUCT.md010064400017500001750000000061521331301131600146410ustar0000000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: - Using welcoming and inclusive language - Being respectful of differing viewpoints and experiences - Gracefully accepting constructive criticism - Focusing on what is best for the community - Showing empathy towards other community members Examples of unacceptable behavior by participants include: - The use of sexualized language or imagery and unwelcome sexual attention or advances - Trolling, insulting/derogatory comments, and personal or political attacks - Public or private harassment - Publishing others' private information, such as a physical or electronic address, without explicit permission - Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at yoshuawuyts@gmail.com, or through IRC. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html man-0.3.0/.github/CONTRIBUTING.md010064400017500001750000000057221331301131600142750ustar0000000000000000# Contributing Contributions include code, documentation, answering user questions, running the project's infrastructure, and advocating for all types of users. The project welcomes all contributions from anyone willing to work in good faith with other contributors and the community. No contribution is too small and all contributions are valued. This guide explains the process for contributing to the project's GitHub Repository. - [Code of Conduct](#code-of-conduct) - [Bad Actors](#bad-actors) - [Developer Certificate of Origin](#developer-certificate-of-origin) ## Code of Conduct The project has a [Code of Conduct][./CODE_OF_CONDUCT.md] that *all* contributors are expected to follow. This code describes the *minimum* behavior expectations for all contributors. As a contributor, how you choose to act and interact towards your fellow contributors, as well as to the community, will reflect back not only on yourself but on the project as a whole. The Code of Conduct is designed and intended, above all else, to help establish a culture within the project that allows anyone and everyone who wants to contribute to feel safe doing so. Should any individual act in any way that is considered in violation of the [Code of Conduct][./CODE_OF_CONDUCT.md], corrective actions will be taken. It is possible, however, for any individual to *act* in such a manner that is not in violation of the strict letter of the Code of Conduct guidelines while still going completely against the spirit of what that Code is intended to accomplish. Open, diverse, and inclusive communities live and die on the basis of trust. Contributors can disagree with one another so long as they trust that those disagreements are in good faith and everyone is working towards a common goal. ## Bad Actors All contributors to tacitly agree to abide by both the letter and spirit of the [Code of Conduct][./CODE_OF_CONDUCT.md]. Failure, or unwillingness, to do so will result in contributions being respectfully declined. A *bad actor* is someone who repeatedly violates the *spirit* of the Code of Conduct through consistent failure to self-regulate the way in which they interact with other contributors in the project. In doing so, bad actors alienate other contributors, discourage collaboration, and generally reflect poorly on the project as a whole. Being a bad actor may be intentional or unintentional. Typically, unintentional bad behavior can be easily corrected by being quick to apologize and correct course *even if you are not entirely convinced you need to*. Giving other contributors the benefit of the doubt and having a sincere willingness to admit that you *might* be wrong is critical for any successful open collaboration. Don't be a bad actor. ## Developer Certificate of Origin All contributors must read and agree to the [Developer Certificate of Origin (DCO)](../CERTIFICATE). The DCO allows us to accept contributions from people to the project, similarly to how a license allows us to distribute our code. man-0.3.0/.github/ISSUE_TEMPLATE.md010064400017500001750000000031231331301131600145420ustar0000000000000000 **Choose one:** is this a 🐛 bug report, a 🙋 feature request, or a 🔦 question? ## Expected Behavior ## Current Behavior ## Possible Solution ## Context ## Code Sample ## Your Environment | Software | Version(s) | | ---------------- | ---------- | | Package | | Runtime | | Package Manager | | Operating System | man-0.3.0/.github/PULL_REQUEST_TEMPLATE.md010064400017500001750000000013301331301131600156340ustar0000000000000000 **Choose one:** is this a 🐛 bug fix, a 🙋 feature, or a 🔦 documentation change? ## Checklist - [ ] tests pass - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added ## Context ## Semver Changes man-0.3.0/.github/stale.yml010064400017500001750000000007141331301131600136730ustar0000000000000000# Configuration for probot-stale - https://github.com/probot/stale daysUntilStale: 90 daysUntilClose: 7 exemptLabels: - pinned - security exemptProjects: false exemptMilestones: false staleLabel: wontfix markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. unmarkComment: false closeComment: false limitPerRun: 30 man-0.3.0/.gitignore010064400017500001750000000001331331302061700124670ustar0000000000000000node_modules/ coverage/ tmp/ dist/ npm-debug.log* .DS_Store .nyc_output target/ Cargo.lock man-0.3.0/.travis.yml010064400017500001750000000003511342035721300126160ustar0000000000000000language: rust before_script: - rustup component add rustfmt-preview - rustup component add clippy-preview script: - cargo fmt --all -- --check - cargo clippy --all -- -D warnings - cargo test --all --verbose cache: cargo man-0.3.0/CERTIFICATE010064400017500001750000000026151331301131600121470ustar0000000000000000Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. man-0.3.0/CHANGELOG.md010064400017500001750000000101321342035724100123150ustar0000000000000000## 2019-01-18, Version 0.2.0 ### Commits - [[`be9f474a8d`](https://github.com/rust-clique/man/commit/be9f474a8d468f1ee5dcbcb265b1622f9d7b4b07)] (cargo-release) version 0.2.0 (Yoshua Wuyts) - [[`ebea68ae03`](https://github.com/rust-clique/man/commit/ebea68ae036d85e675cfed68e0f81ea3c8f61048)] Add custom section (#24) (Daniel Sockwell) - [[`dd0ae08a4d`](https://github.com/rust-clique/man/commit/dd0ae08a4d7a3e5fbe6a5ba6c7921bd4243b8322)] Merge pull request #23 from codesections/README-example (Dylan DPC) - [[`5f703ae61a`](https://github.com/rust-clique/man/commit/5f703ae61a54881420a56428fb4469e3806e3042)] fmt (dylan_DPC) - [[`f876dd271d`](https://github.com/rust-clique/man/commit/f876dd271d888c3883ed4f86ed962ca9dd223726)] Clarify installation instructions (Daniel Sockwell) - [[`3c4d7c27a1`](https://github.com/rust-clique/man/commit/3c4d7c27a1e090160f11ec908a1108d7949b0569)] Fix usage example (Daniel Sockwell) - [[`48882c80fa`](https://github.com/rust-clique/man/commit/48882c80fa711c2a561aa93486bbe243a1262673)] Update changelog (Yoshua Wuyts) ### Stats ```diff CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- README.md | 48 +++++++++++++++++++++++++++++++++++------------- examples/main.rs | 17 +++++++++++++---- src/lib.rs | 2 ++ src/man.rs | 34 ++++++++++++++++++++++++++++++++++ src/mod.rs | 9 ++++----- src/prelude.rs | 1 + src/section.rs | 20 ++++++++++++++++++++ 9 files changed, 144 insertions(+), 23 deletions(-) ``` ## 2018-11-07, Version 0.1.1 ### Commits - [[`163c3a0cbe`](https://github.com/rust-clique/man/commit/163c3a0cbe54af4e8431ed1ae72cc413d5dbf5ed)] (cargo-release) version 0.1.1 (Yoshua Wuyts) - [[`892ac22c36`](https://github.com/rust-clique/man/commit/892ac22c36b07b6731464a4ef104c44bcc623c44)] Merge pull request #20 from killercup/ci (Dylan DPC) - [[`e9466baf2b`](https://github.com/rust-clique/man/commit/e9466baf2b125b4a90818b92a301d45ea6cfe489)] clippy (Pascal Hertleif) - [[`47d317f0ac`](https://github.com/rust-clique/man/commit/47d317f0acf2d4cdc44875833e27fc3ed19b3e69)] rustfmt (Pascal Hertleif) - [[`33a01f330e`](https://github.com/rust-clique/man/commit/33a01f330ed80d1f6cc4fb4d8d2c5def74b2b1ce)] Update travis settings (Pascal Hertleif) - [[`cd8f1d5d88`](https://github.com/rust-clique/man/commit/cd8f1d5d88ba1522af7f7c9839b2e9a76b1a0efa)] Merge pull request #13 from rust-clique/docs (Pascal Hertleif) - [[`4c848d3b65`](https://github.com/rust-clique/man/commit/4c848d3b65f18b4edd01b92a8106cc6c2768ebdf)] Merge pull request #19 from Kixunil/section-description (Pascal Hertleif) - [[`542fe19b31`](https://github.com/rust-clique/man/commit/542fe19b31334f9c7827d81923d3d51db92c3ae9)] Added description section. (Martin Habovstiak) - [[`904b4c4193`](https://github.com/rust-clique/man/commit/904b4c4193bf70d7641b14f5f642fed26612fe2c)] Use correct name (#16) (Jan-Erik Rediger) - [[`2e64a4e637`](https://github.com/rust-clique/man/commit/2e64a4e6370f83a40d17fc96be5db1fade747a98)] Accept everything that can be turned into a string (#15) (Jan-Erik Rediger) - [[`3ee6dbbd3a`](https://github.com/rust-clique/man/commit/3ee6dbbd3ac5b624a49413c77e7be2ae1f8b2a96)] document more (Yoshua Wuyts) - [[`ede4e240c9`](https://github.com/rust-clique/man/commit/ede4e240c93b2ba22b39e6bbc835710df91b13f5)] Merge pull request #12 from rust-clique/example (Dylan DPC) - [[`16d8709b14`](https://github.com/rust-clique/man/commit/16d8709b1404d3443bb6a9d179629a1bcafb1d3b)] add example output (Yoshua Wuyts) - [[`53a03672c3`](https://github.com/rust-clique/man/commit/53a03672c3a256c550c070aa634c0d41a665d052)] (cargo-release) start next development iteration 0.1.1-alpha.0 (Yoshua Wuyts) ### Stats ```diff .travis.yml | 17 +++++++---------- Cargo.toml | 2 +- README.md | 36 ++++++++++++++++++++++++++++++++++-- examples/main.rs | 14 +++++--------- src/arg.rs | 1 + src/author.rs | 2 +- src/environment.rs | 2 +- src/flag.rs | 10 +++------- src/man.rs | 43 ++++++++++++++++++++++++++++++++++--------- src/option.rs | 2 +- src/prelude.rs | 2 +- 11 files changed, 89 insertions(+), 42 deletions(-) ``` man-0.3.0/Cargo.toml.orig010064400017500001750000000005101342165465000133770ustar0000000000000000[package] name = "man" version = "0.3.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-clique/man" documentation = "https://docs.rs/man" description = "Generate structured man pages" authors = ["Yoshua Wuyts "] readme = "README.md" [dependencies] roff = "0.1.0" [dev-dependencies] man-0.3.0/Cargo.toml0000644000000015330000000000000076460ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "man" version = "0.3.0" authors = ["Yoshua Wuyts "] description = "Generate structured man pages" documentation = "https://docs.rs/man" readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-clique/man" [dependencies.roff] version = "0.1.0" [dev-dependencies] man-0.3.0/LICENSE-APACHE010064400017500001750000000250051331301131600124240ustar0000000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Copyright 2018 Yoshua Wuyts Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. man-0.3.0/LICENSE-MIT010064400017500001750000000020671331301131600121370ustar0000000000000000The MIT License (MIT) Copyright (c) 2018 Yoshua Wuyts Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", 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. man-0.3.0/README.md010064400017500001750000000056761342165464500120150ustar0000000000000000# man [![crates.io version][1]][2] [![build status][3]][4] [![downloads][5]][6] [![docs.rs docs][7]][8] Generate structured man pages using [roff-rs](https://github.com/killercup/roff-rs). - [Documentation][8] - [Crates.io][2] ## Usage ```rust use man::prelude::*; fn main() { let page = Manual::new("basic") .about("A basic example") .author(Author::new("Alice Person").email("alice@person.com")) .author(Author::new("Bob Human").email("bob@human.com")) .flag( Flag::new() .short("-d") .long("--debug") .help("Enable debug mode"), ) .flag( Flag::new() .short("-v") .long("--verbose") .help("Enable verbose mode"), ) .option( Opt::new("output") .short("-o") .long("--output") .help("The file path to write output to"), ) .example( Example::new() .text("run basic in debug mode") .command("basic -d") .output("Debug Mode: basic will print errors to the console") ) .custom( Section::new("usage note") .paragraph("This program will overwrite any file currently stored at the output path") ) .render(); println!("{}", page); } ``` Preview by running: ```sh $ cargo run > /tmp/app.man; man /tmp/app.man ``` Which outputs: ```txt BASIC(1) General Commands Manual BASIC(1) NAME basic - A basic example SYNOPSIS basic [FLAGS] [OPTIONS] FLAGS -d, --debug Enable debug mode -v, --verbose Enable verbose mode OPTIONS -o, --output=output The file path to write output to USAGE NOTE This file will overwrite any file currently stored at the output path. EXIT STATUS 0 Successful program execution. 1 Unsuccessful program execution. 101 The program panicked. EXAMPLES run basic in debug mode $ basic -d Debug Mode: basic will print errors to the console AUTHORS Alice Person Bob Human ``` ## Installation If using [cargo-edit](https://github.com/killercup/cargo-edit), install with ```sh $ cargo add man ``` Otherwise, install by adding to Cargo.toml file's dependency section. ## License [MIT](./LICENSE-MIT) OR [Apache-2.0](./LICENSE-APACHE) [1]: https://img.shields.io/crates/v/man.svg?style=flat-square [2]: https://crates.io/crates/man [3]: https://img.shields.io/travis/rust-clique/man.svg?style=flat-square [4]: https://travis-ci.org/rust-clique/man [5]: https://img.shields.io/crates/d/man.svg?style=flat-square [6]: https://crates.io/crates/man [7]: https://docs.rs/man/badge.svg [8]: https://docs.rs/man man-0.3.0/examples/main.rs010064400017500001750000000027351342165464500136370ustar0000000000000000extern crate man; use man::prelude::*; fn main() { let msg = Manual::new("auth-service") .about("authorize & authenticate members") .arg(Arg::new("path")) .env(Env::new("PORT").help("The network port to listen to")) .flag( Flag::new() .short("-h") .long("--help") .help("Prints help information."), ) .flag( Flag::new() .short("-V") .long("--version") .help("Prints version information."), ) .flag( Flag::new() .short("-v") .long("--verbosity") .help("Pass multiple times to print more information."), ) .option( Opt::new("port") .short("-p") .long("--port") .help("The network port to listen to."), ) .example( Example::new() .text("listen on port 3000") .command("auth-service -p 3000") .output("now listening on port 3000"), ) .example( Example::new() .text("auth-service may need to be run by root") .prompt("#") .command("auth-service"), ) .custom( Section::new("custom section") .paragraph("text for the custom section") .paragraph("Additional text for the custom section"), ) .author(Author::new("Alice Person").email("alice@person.com")) .author(Author::new("Bob Human").email("bob@human.com")) .render(); // .option(Some("-o"), Some("--output"), "output", None, "Output file"); println!("{}", msg); } man-0.3.0/rustfmt.toml010064400017500001750000000000361331301131600130760ustar0000000000000000max_width = 80 tab_spaces = 2 man-0.3.0/src/arg.rs010064400017500001750000000002641342035721300124160ustar0000000000000000/// Positional arguments. #[derive(Debug, Clone)] pub struct Arg { pub(crate) name: String, } impl Arg { pub fn new(name: &str) -> Self { Self { name: name.into() } } } man-0.3.0/src/author.rs010064400017500001750000000006261342035721300131510ustar0000000000000000/// Application authors. #[derive(Debug, Clone)] pub struct Author { pub(crate) name: String, pub(crate) email: Option, } impl Author { /// Create a new instance. pub fn new(name: &str) -> Self { Self { name: name.into(), email: None, } } /// Set the email field. pub fn email(mut self, email: &str) -> Self { self.email = Some(email.into()); self } } man-0.3.0/src/environment.rs010064400017500001750000000011511342035721300142050ustar0000000000000000/// Arguments that are passed by the executing shell. #[derive(Debug, Clone)] pub struct Env { pub(crate) name: String, pub(crate) default: Option, pub(crate) help: Option, } impl Env { /// Create a new instance. pub fn new(name: &str) -> Self { Self { name: name.into(), default: None, help: None, } } /// Set the default value. pub fn default_value(mut self, default: &str) -> Self { self.default = Some(default.into()); self } /// Set the help. pub fn help(mut self, help: &str) -> Self { self.help = Some(help.into()); self } } man-0.3.0/src/example.rs010064400017500001750000000014321342165464500133100ustar0000000000000000/// Add a examples section #[derive(Debug, Clone, Default)] pub struct Example { pub(crate) prompt: &'static str, pub(crate) text: Option<&'static str>, pub(crate) command: Option<&'static str>, pub(crate) output: Option<&'static str>, } impl Example { pub fn new() -> Self { Self { prompt: "$", text: None, command: None, output: None, } } pub fn prompt(mut self, prompt: &'static str) -> Self { self.prompt = prompt; self } pub fn text(mut self, text: &'static str) -> Self { self.text = Some(text); self } pub fn command(mut self, command: &'static str) -> Self { self.command = Some(command); self } pub fn output(mut self, output: &'static str) -> Self { self.output = Some(output); self } } man-0.3.0/src/flag.rs010064400017500001750000000012411342035721300125520ustar0000000000000000/// Boolean arguments that can be toggled on or off. #[derive(Debug, Clone, Default)] pub struct Flag { pub(crate) short: Option, pub(crate) long: Option, pub(crate) help: Option, } impl Flag { /// Create a new instance. pub fn new() -> Self { Self::default() } /// Set the short value. pub fn short(mut self, short: &str) -> Self { self.short = Some(short.into()); self } /// Set the long value. pub fn long(mut self, long: &str) -> Self { self.long = Some(long.into()); self } /// Set the help value. pub fn help(mut self, help: &str) -> Self { self.help = Some(help.into()); self } } man-0.3.0/src/lib.rs010064400017500001750000000010201342165464500124140ustar0000000000000000#![cfg_attr(feature = "nightly", deny(missing_docs))] #![cfg_attr(feature = "nightly", feature(external_doc))] #![cfg_attr(feature = "nightly", doc(include = "../README.md"))] #![cfg_attr(test, deny(warnings))] extern crate roff; mod arg; mod author; mod environment; mod example; mod flag; mod man; mod option; mod section; pub mod prelude; pub use arg::Arg; pub use author::Author; pub use environment::Env; pub use example::Example; pub use flag::Flag; pub use man::Manual; pub use option::Opt; pub use section::Section; man-0.3.0/src/man.rs010064400017500001750000000245601342165464500124370ustar0000000000000000use super::*; use roff::{bold, italic, list, Roff, Troffable}; /// The main man page struct. #[derive(Debug, Clone)] pub struct Manual { name: String, about: Option, description: Option, authors: Vec, flags: Vec, options: Vec, environment: Vec, arguments: Vec, custom_sections: Vec
, examples: Vec, } impl Manual { /// Create a new instance. pub fn new(name: &str) -> Self { Self { name: name.into(), about: None, description: None, authors: vec![], flags: vec![], options: vec![], arguments: vec![], environment: vec![], custom_sections: vec![], examples: vec![], } } /// Add a short description. pub fn about>(mut self, about: S) -> Self { self.about = Some(about.into()); self } /// Add a long description. pub fn description>(mut self, description: S) -> Self { self.description = Some(description.into()); self } /// Add an author. pub fn author(mut self, author: Author) -> Self { self.authors.push(author); self } /// Add an environment variable. pub fn env(mut self, env: Env) -> Self { self.environment.push(env); self } /// Add an flag. pub fn flag(mut self, flag: Flag) -> Self { self.flags.push(flag); self } /// Add an option. pub fn option(mut self, opt: Opt) -> Self { self.options.push(opt); self } /// Add a custom section pub fn custom(mut self, custom_section: Section) -> Self { self.custom_sections.push(custom_section); self } /// Add an examples section pub fn example(mut self, example: Example) -> Self { self.examples.push(example); self } /// Add a positional argument. The items are displayed in the order they're /// pushed. // TODO: make this accept argument vecs / optional args too. `arg...`, `arg?` pub fn arg(mut self, arg: Arg) -> Self { self.arguments.push(arg); self } /// Render to a string. pub fn render(self) -> String { let man_num = 1; let mut page = Roff::new(&self.name, man_num); page = about(page, &self.name, &self.about); page = synopsis( page, &self.name, &self.flags, &self.options, &self.arguments, ); page = description(page, &self.description); page = flags(page, &self.flags); page = options(page, &self.options); page = env(page, &self.environment); for section in self.custom_sections.into_iter() { page = custom(page, section); } page = exit_status(page); page = examples(page, &self.examples); page = authors(page, &self.authors); page.render() } } /// Create a `NAME` section. /// /// ## Formatting /// ```txt /// NAME /// mycmd - brief help of the application /// ``` fn about(page: Roff, name: &str, desc: &Option) -> Roff { let desc = match desc { Some(ref desc) => format!("{} - {}", name, desc), None => name.to_owned(), }; page.section("NAME", &[desc]) } /// Create a `DESCRIPTION` section. /// /// ## Formatting /// ```txt /// DESCRIPTION /// Very long description of the application /// ``` fn description(page: Roff, desc: &Option) -> Roff { if let Some(desc) = desc { page.section("DESCRIPTION", &[desc.to_owned()]) } else { page } } /// Create a `SYNOPSIS` section. fn synopsis( page: Roff, name: &str, flags: &[Flag], options: &[Opt], args: &[Arg], ) -> Roff { let flags = match flags.len() { 0 => "".into(), _ => " [FLAGS]".into(), }; let options = match options.len() { 0 => "".into(), _ => " [OPTIONS]".into(), }; let mut msg = vec![]; msg.push(bold(name)); msg.push(flags); msg.push(options); for arg in args { msg.push(format!(" {}", arg.name)); } page.section("SYNOPSIS", &msg) } /// Create a `AUTHOR` or `AUTHORS` section. /// /// ## Formatting /// ```txt /// AUTHORS /// Alice Person /// Bob Human /// ``` fn authors(page: Roff, authors: &[Author]) -> Roff { let title = match authors.len() { 0 => return page, 1 => "AUTHOR", _ => "AUTHORS", }; let last = authors.len() - 1; let mut auth_values = vec![]; auth_values.push(init_list()); for (index, author) in authors.iter().enumerate() { auth_values.push(author.name.to_owned()); if let Some(ref email) = author.email { auth_values.push(format!(" <{}>", email)) }; if index != last { auth_values.push(String::from("\n")); } } page.section(title, &auth_values) } /// Create a `FLAGS` section. /// /// ## Formatting /// ```txt /// FLAGS /// ``` fn flags(page: Roff, flags: &[Flag]) -> Roff { if flags.is_empty() { return page; } let last = flags.len() - 1; let mut arr: Vec = vec![]; for (index, flag) in flags.iter().enumerate() { let mut args: Vec = vec![]; if let Some(ref short) = flag.short { args.push(bold(&short)); } if let Some(ref long) = flag.long { if !args.is_empty() { args.push(", ".to_string()); } args.push(bold(&long)); } let desc = match flag.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(String::from("\n\n")); } } page.section("FLAGS", &arr) } /// Create a `OPTIONS` section. /// /// ## Formatting /// ```txt /// OPTIONS /// ``` fn options(page: Roff, options: &[Opt]) -> Roff { if options.is_empty() { return page; } let last = options.len() - 1; let mut arr: Vec = vec![]; for (index, opt) in options.iter().enumerate() { let mut args: Vec = vec![]; if let Some(ref short) = opt.short { args.push(bold(&short)); } if let Some(ref long) = opt.long { if !args.is_empty() { args.push(", ".to_string()); } args.push(bold(&long)); } args.push("=".into()); args.push(italic(&opt.name)); if let Some(ref default) = opt.default { if !args.is_empty() { args.push(" ".to_string()); } args.push("[".into()); args.push("default:".into()); args.push(" ".into()); args.push(italic(&default)); args.push("]".into()); } let desc = match opt.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(String::from("\n\n")); } } page.section("OPTIONS", &arr) } /// Create a `ENVIRONMENT` section. /// /// ## Formatting /// /// ```txt /// ENVIRONMENT /// ``` fn env(page: Roff, environment: &[Env]) -> Roff { if environment.is_empty() { return page; } let last = environment.len() - 1; let mut arr: Vec = vec![]; for (index, env) in environment.iter().enumerate() { let mut args: Vec = vec![]; args.push(bold(&env.name)); if let Some(ref default) = env.default { if !args.is_empty() { args.push(" ".to_string()); } args.push("[".into()); args.push("default:".into()); args.push(" ".into()); args.push(italic(&default)); args.push("]".into()); } let desc = match env.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(String::from("\n\n")); } } page.section("ENVIRONMENT", &arr) } /// Create a `EXIT STATUS` section. /// /// ## Implementation Note /// This currently only returns the status code `0`, and takes no arguments. We /// should let it take arguments. /// /// ## Formatting /// ```txt /// EXIT STATUS /// 0 Successful program execution /// /// 1 Usage, syntax or configuration file error /// /// 2 Optional error /// ``` fn exit_status(page: Roff) -> Roff { page.section( "EXIT STATUS", &[ list(&[bold("0")], &["Successful program execution.\n\n"]), list(&[bold("1")], &["Unsuccessful program execution.\n\n"]), list(&[bold("101")], &["The program panicked."]), ], ) } /// Create a custom section. /// /// The custom section will have the title you specify as the argument to the /// .new() method and may optionally be followed by one or more paragraphs /// using the .paragraph() method. /// /// ## Formatting /// ```txt /// SECTION NAME /// Text of first paragraph /// /// Text of second paragraph /// /// ``` fn custom(page: Roff, custom_section: Section) -> Roff { let mut paragraphs: Vec = vec![]; for paragraph in custom_section.paragraphs.into_iter() { paragraphs.push(paragraph); paragraphs.push("\n\n".into()) } page.section(&custom_section.name, ¶graphs) } /// Create an examples section /// /// examples can have text (shown before the example command) and the command /// itself. Optionally, you can also display the output of the command, but /// this is typically not necessary. You may also change the prompt displayed /// before the command (the default is `$`). /// /// The command is printed in bold. /// /// ## Formatting /// ```txt /// EXAMPLES /// Explanatory text /// $ command /// output /// ``` fn examples(page: Roff, examples: &[Example]) -> Roff { if examples.is_empty() { return page; }; let mut arr = vec![]; for example in examples { let text = example.text.unwrap_or(""); let mut full_command = String::from(example.prompt); if let Some(command) = example.command { full_command.push_str(" "); full_command.push_str(command); }; let output = match example.output { Some(output) => { // For now, we need to manually add the line break in the list // see https://github.com/killercup/roff-rs/issues/5 let mut full_output = String::from("\n.br\n"); full_output.push_str(output); full_output.push_str("\n"); full_output } None => String::from("\n"), }; let example = list(&[text], &[bold(full_command.as_str()), output]); arr.push(example); } page.section("examples", &arr) } // NOTE(yw): This code was taken from the npm-install(1) command. The location // on your system may vary. In all honesty I just copy-pasted this. We should // probably port this to troff-rs at some point. // // ```sh // $ less /usr/share/man/man1/npm-install.1 // ``` fn init_list() -> String { String::from(".P\n.RS 2\n.nf\n") } man-0.3.0/src/mod.rs010064400017500001750000000175221342035721300124310ustar0000000000000000mod author; mod custom; mod environment; mod flag; mod option; use self::author::Author; use self::custom::Para; use self::environment::Env; use self::flag::Flag; use self::option::Opt; use roff::{bold, italic, list, Roff, Troffable}; use std::convert::AsRef; /// Man page struct. #[derive(Debug, Clone)] pub struct Man { name: String, help: Option, authors: Vec, flags: Vec, options: Vec, environment: Vec, arguments: Vec, custom: Vec, } impl Man { /// Create a new instance. pub fn new(name: &str) -> Self { Self { name: name.into(), help: None, authors: vec![], flags: vec![], options: vec![], arguments: vec![], environment: vec![], } } /// Add a help. pub fn help(mut self, desc: &str) -> Self { let desc = desc.into(); self.help = Some(desc); self } /// Add an author. pub fn author( mut self, name: impl AsRef, email: Option, ) -> Self { self.authors.push(Author { name: name.as_ref().to_owned(), email, }); self } /// Add an environment variable. pub fn environment( mut self, name: String, default: Option, help: Option, ) -> Self { self.environment.push(Env { name, default, help, }); self } /// Add an flag. pub fn flag( mut self, short: Option, long: Option, help: Option, ) -> Self { self.flags.push(Flag { short, long, help }); self } /// Add an option. pub fn option( mut self, short: Option, long: Option, help: Option, argument: String, default: Option, ) -> Self { self.options.push(Opt { short, long, help, argument, default, }); self } /// Add a positional argument. The items are displayed in the order they're /// pushed. // TODO: make this accept argument vecs / optional args too. `arg...`, `arg?` pub fn argument(mut self, arg: String) -> Self { self.arguments.push(arg); self } pub fn render(self) -> String { let man_num = 1; let mut page = Roff::new(&self.name, man_num); page = help(page, &self.name, &self.help); page = synopsis( page, &self.name, &self.flags, &self.options, &self.arguments, ); page = flags(page, &self.flags); page = options(page, &self.options); page = environment(page, &self.environment); page = exit_status(page); page = authors(page, &self.authors); page.render() } } /// Create a `NAME` section. /// /// ## Formatting /// ```txt /// NAME /// mycmd - brief help of the application /// ``` fn help(page: Roff, name: &str, desc: &Option) -> Roff { let desc = match desc { Some(ref desc) => format!("{} - {}", name, desc), None => name.to_owned(), }; page.section("NAME", &[desc]) } /// Create a `SYNOPSIS` section. fn synopsis( page: Roff, name: &str, flags: &[Flag], options: &[Opt], args: &[String], ) -> Roff { let flags = match flags.len() { 0 => "".into(), _ => " [FLAGS]".into(), }; let options = match options.len() { 0 => "".into(), _ => " [OPTIONS]".into(), }; let mut msg = vec![]; msg.push(bold(name)); msg.push(flags); msg.push(options); for arg in args { msg.push(format!(" {}", arg)); } page.section("SYNOPSIS", &msg) } /// Create a `AUTHOR` or `AUTHORS` section. /// /// ## Formatting /// ```txt /// AUTHORS /// Alice Person /// Bob Human /// ``` fn authors(page: Roff, authors: &[Author]) -> Roff { let title = match authors.len() { 0 => return page, 1 => "AUTHOR", _ => "AUTHORS", }; let last = authors.len() - 1; let mut auth_values = vec![]; auth_values.push(init_list()); for (index, author) in authors.iter().enumerate() { auth_values.push(author.name.to_owned()); if let Some(ref email) = author.email { auth_values.push(format!(" <{}>", email)) }; if index != last { auth_values.push(format!("\n")); } } page.section(title, &auth_values) } /// Create a `FLAGS` section. /// /// ## Formatting /// ```txt /// FLAGS /// ``` fn flags(page: Roff, flags: &[Flag]) -> Roff { if flags.is_empty() { return page; } let last = flags.len() - 1; let mut arr: Vec = vec![]; for (index, flag) in flags.iter().enumerate() { let mut args: Vec = vec![]; if let Some(ref short) = flag.short { args.push(bold(&short)); } if let Some(ref long) = flag.long { if !args.is_empty() { args.push(", ".to_string()); } args.push(bold(&long)); } let desc = match flag.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(format!("\n\n")); } } page.section("FLAGS", &arr) } /// Create a `OPTIONS` section. /// /// ## Formatting /// ```txt /// OPTIONS /// ``` fn options(page: Roff, options: &[Opt]) -> Roff { if options.is_empty() { return page; } let last = options.len() - 1; let mut arr: Vec = vec![]; for (index, opt) in options.iter().enumerate() { let mut args: Vec = vec![]; if let Some(ref short) = opt.short { args.push(bold(&short)); } if let Some(ref long) = opt.long { if !args.is_empty() { args.push(", ".to_string()); } args.push(bold(&long)); } args.push("=".into()); args.push(italic(&opt.argument)); if let Some(ref default) = opt.default { if !args.is_empty() { args.push(" ".to_string()); } args.push("[".into()); args.push("default:".into()); args.push(" ".into()); args.push(italic(&default)); args.push("]".into()); } let desc = match opt.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(format!("\n\n")); } } page.section("OPTIONS", &arr) } /// Create a `ENVIRONMENT` section. /// /// ## Formatting /// ```txt /// ENVIRONMENT /// ``` fn environment(page: Roff, environment: &[Env]) -> Roff { if environment.is_empty() { return page; } let last = environment.len() - 1; let mut arr: Vec = vec![]; for (index, env) in environment.iter().enumerate() { let mut args: Vec = vec![]; args.push(bold(&env.name)); if let Some(ref default) = env.default { if !args.is_empty() { args.push(" ".to_string()); } args.push("[".into()); args.push("default:".into()); args.push(" ".into()); args.push(italic(&default)); args.push("]".into()); } let desc = match env.help { Some(ref desc) => desc.to_string(), None => "".to_string(), }; arr.push(list(&args, &[desc])); if index != last { arr.push(format!("\n\n")); } } page.section("ENVIRONMENT", &arr) } /// Create a `EXIT STATUS` section. /// /// ## Implementation Note /// This currently only returns the status code `0`, and takes no arguments. We /// should let it take arguments. /// /// ## Formatting /// ```txt /// EXIT STATUS /// 0 Successful program execution /// /// 1 Usage, syntax or configuration file error /// /// 2 Optional error /// ``` fn exit_status(page: Roff) -> Roff { page.section( "EXIT STATUS", &[list(&[bold("0")], &["Successful program execution."])], ) } // NOTE(yw): This code was taken from the npm-install(1) command. The location // on your system may vary. In all honesty I just copy-pasted this. We should // probably port this to troff-rs at some point. // // ```sh // $ less /usr/share/man/man1/npm-install.1 // ``` fn init_list() -> String { format!(".P\n.RS 2\n.nf\n") } man-0.3.0/src/option.rs010064400017500001750000000016661342035721300131640ustar0000000000000000/// Arguments that take values. #[derive(Debug, Clone)] pub struct Opt { pub(crate) name: String, pub(crate) default: Option, pub(crate) help: Option, pub(crate) short: Option, pub(crate) long: Option, } impl Opt { /// Create a new instance. pub fn new(name: &str) -> Self { Self { name: name.into(), default: None, help: None, short: None, long: None, } } /// Set the default value. pub fn default_value(mut self, default: &str) -> Self { self.default = Some(default.into()); self } /// Set the help. pub fn help(mut self, help: &str) -> Self { self.help = Some(help.into()); self } /// Set the short value. pub fn short(mut self, short: &str) -> Self { self.short = Some(short.into()); self } /// Set the long value. pub fn long(mut self, long: &str) -> Self { self.long = Some(long.into()); self } } man-0.3.0/src/prelude.rs010064400017500001750000000006111342165464500133130ustar0000000000000000//! Convenience wrapper to import all the essential structs. //! //! ```rust //! extern crate man; //! //! use man::prelude::*; //! //! fn main () { //! let msg = Manual::new("my-app").render(); //! } //! ``` pub use arg::Arg; pub use author::Author; pub use environment::Env; pub use example::Example; pub use flag::Flag; pub use man::Manual; pub use option::Opt; pub use section::Section; man-0.3.0/src/section.rs010064400017500001750000000005561342035721300133150ustar0000000000000000/// Add a custom section #[derive(Debug, Clone)] pub struct Section { pub(crate) name: String, pub(crate) paragraphs: Vec, } impl Section { pub fn new(name: &str) -> Self { Self { name: name.into(), paragraphs: vec![], } } pub fn paragraph(mut self, text: &str) -> Self { self.paragraphs.push(text.into()); self } } man-0.3.0/.cargo_vcs_info.json0000644000000001120000000000000116400ustar00{ "git": { "sha1": "cb87621fac17ebfd661ce69b1d64527375227e14" } }