RBCli Documentation https://akhoury6.github.io/rbcli/ Recent content on RBCli Documentation Hugo -- gohugo.io en-us Thu, 20 Jun 2019 15:07:21 -0400 Contribution Guide https://akhoury6.github.io/rbcli/development/contributing/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/development/contributing/ Contributing to RBCli is the same as most open source projects: Fork the repository Create your own branch Submit a pull request when ready That’s all there is to it! We’ve also kept our acceptance criteria pretty simple, as you’ll see below. Feel free to submit a pull request even if you don’t meet it if you would like your code or feature to be reviewed first; we do want to be mindful of your time and will review submissions before they are polished. Getting Started https://akhoury6.github.io/rbcli/tutorial/10-getting_started/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/tutorial/10-getting_started/ Welcome to the RBCli getting started tutorial! In this tutorial we’re going to cover the basics of RBCli and get a simple application up and running. It should take you between 30-60 minutes to complete, depending on your skill level with Ruby. As you go throught the tutorial, you can either use the Next and Back buttons on the page to navigate, or use the menu directly. Supported Ruby Versions You’ll need Ruby installed before you can use RBCli. License Info https://akhoury6.github.io/rbcli/development/license/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/development/license/ How RBCli is Licensed We want to help the developer community build tooling faster and with less work. That’s why RBCli was built. And let’s face it - most of us aren’t lawyers, and don’t want to worry about legal fine print when building awesome software. That’s why RBCli is released under the GPLv3 License. So you’re free to use RBCli as you see fit to write free software. If you wish to use RBCli in a commercial offering, please contact me at andrew@blacknex. The Project Layout https://akhoury6.github.io/rbcli/tutorial/20-project_layout/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/tutorial/20-project_layout/ Now we will learn about what an RBCli project looks like and how to start using it. Project Initialization Types RBCli can initialize a tool in three different modes: Project Mode (default) Mini Mode Micro Mode Project Mode If you’ve been following along with the tutorial, you’ve already seen Project Mode. An RBCli Project consists of several folders, each of which has a specific function. The RBCli framework handles loading and parsing the code automatically. Code of Conduct https://akhoury6.github.io/rbcli/development/code_of_conduct/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/development/code_of_conduct/ The 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, nationality, personal appearance, race, religion, or sexual identity and orientation. Our Standards Examples of behavior that contributes to creating a positive environment include: Your First Command https://akhoury6.github.io/rbcli/tutorial/30-your_first_command/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/tutorial/30-your_first_command/ Creating the Command Creating the command is straightforward: rbcli command --name=list #or rbcli command -n list And there you have it! Now you can try out your command by typing: ./exe/mytool list Congrats! You should now see a generic output listing the values of several variables. We’ll get into what they mean in a bit, but first, let’s make the tool’s execution a bit easier. Now that you know your way around a project, its time to create your first command! Options, Parameters, and Arguments https://akhoury6.github.io/rbcli/tutorial/40-options_parameters_and_arguments/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/tutorial/40-options_parameters_and_arguments/ If you’re already an experienced coder, you can jump to the last section of this document, the Simplified Reference (TLDR) Command Line Structure In the previous section, you saw two parts of the RBCli command line structure - the executable followed by the command. However, RBCli is capable of more complex interaction. The structure is as follows: toolname [options] command [parameters] argument1 argument2... Options are command line parameters such as -f, or --force. Publishing Your Application https://akhoury6.github.io/rbcli/tutorial/50-publishing/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/tutorial/50-publishing/ RBCli creates projects designed to be easily distributed via either source control or as a gem. We’ll go over both methods. Common Tasks Regardless of where you are publishing, certain tasks need to be accomplished. Namely, preparing the gemspec and the README. In both files the items that need changing are pretty obvious – you’ll need to fill out your name, email, etc, and replace the placeholder text in the README with something useful to your users. Changelog https://akhoury6.github.io/rbcli/development/changelog/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/development/changelog/ 0.2.12 (Unreleased) Improvements The base project skeleton now includes an improved structure for the lib/ folder Documentation now uses Hugo instead of MkDocs for site generation. Updated dependencies in project skeleton to latest versions Features Development mode can be enabled by setting the environment variables: RBCLI_ENV=development and RBCLI_DEVPATH=[path to local Rbcli folder] to simplify changes to Rbcli during development. Combined with setting alias rbcli='/path/to/rbcli/exe/rbcli', gem installation is not required for development work 0. Automatic Updates https://akhoury6.github.io/rbcli/advanced/automatic_updates/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/automatic_updates/ RBCli can automatically notify users when an update is available. If force_update is set (see below), RBCli can halt execution until the user updates their application. Two sources are currently supported: Github (including Enterprise) and RubyGems. GitHub Update Check The GitHub update check works best when paired with GitHub’s best practices on releases, where new releases are tagged on master with the format vX.X.X. See Github’s release documentation to learn more. Command Types https://akhoury6.github.io/rbcli/advanced/command_types/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/command_types/ RBCli has three different command types: Standard Commands (Ruby-based) Scripted Commands (Ruby+Bash based) External Commands (Wrapping a 3rd party application) This document is provided to be a reference. If you would like an in-depth tutorial, please see Your First Command. General Command Structure Commands in RBCli are created by subclassing Rbcli::Command. All commands share a certain common structure: class List < Rbcli::Command # Declare a new command by subclassing Rbcli::Command description 'TODO: Description goes here' # (Required) Short description for the global help usage <<-EOF TODO: Usage text goes here EOF # (Required) Long description for the command-specific help parameter :force, 'Force testing', type: :boolean, default: false, required: false # (Optional, Multiple) Add a command-specific CLI parameter. Distributed State and Locking https://akhoury6.github.io/rbcli/advanced/distributed_state_locking/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/distributed_state_locking/ Distributed Locking allows a Remote State to be shared among multiple users of the application to make writes appear atomic between sessions. To use it, simply set the locking: parameter to true when enabling remote state. This is how locking works: The application attempts to acquire a lock on the remote state when you first access it If the backend is locked by a different application, wait and try again If it succeeds, the lock is held and refreshed periodically When the application exits, the lock is released If the application does not refresh its lock, or fails to release it when it exits, the lock will automatically expire within 60 seconds If another application steals the lock (unlikely but possible), and the application tries to save data, a StandardError will be thrown You can manually attempt to lock/unlock by calling Rbcli. Execution Hooks https://akhoury6.github.io/rbcli/advanced/hooks/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/hooks/ RBCli provides you with hooks that can be used to have code execute at certain places in the execution chain. These hooks are optional, and do not have to be defined for your application to run. All hooks will be created in the hooks/ folder in your project. The Defailt Action Hook The Default hook is called when a user calls your application without providing a command. If the hook is not provided, the application will automatically display the help text (the same as running it with -h). Interactive Commands https://akhoury6.github.io/rbcli/advanced/interactive_commands/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/interactive_commands/ Why interactive commands? When catering to an audience of users who are not accustomed to scripting, you may want to prompt them for the information directly (the typical CS-101 ‘puts’ and ‘gets’ pattern). This can be a lot more straightforward than having to read the help texts of your tool, and trying multiple times to enter all of the required data. Of course, we want to make sure that scripting with the tool still works well (headless interaction). Logging https://akhoury6.github.io/rbcli/advanced/logging/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/logging/ Logging with RBCli is straightforward - it looks at the config file for logging settings, and instantiates a single, globally accessible Logger object. You can access it within a standard command like this: Rbcli::log.info { 'These logs can go to STDERR, STDOUT, or a file' } Enabling Logging To enable logging, simply set the default values in the config/logging.rb file: log_level :info log_target 'stderr' log_level You can set the default log level using either numeric or standard Ruby logger levels: 0-5, or DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN log_target This specifies where the logs will be placed. Remote Execution https://akhoury6.github.io/rbcli/advanced/remote_execution/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/remote_execution/ RBCli can be configured to execute commands on a remote machine via SSH instead of locally. Currently, only script and extern commands are supported. Configuration To allow remote execution, go to config/general.rb and change the following line to true: remote_execution permitted: false Then, for each command that you would like to enable remote execution for, add the following directive to the command class declaration: remote_permitted Usage Your end users can now execute a command remotely by specifying the connection string and credentials on the command line as follows: State Storage https://akhoury6.github.io/rbcli/advanced/state_storage/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/state_storage/ RBCli supports both local and remote state storage. This is done by synchronizing a Hash with either the local disk or a remote database. Local State RBCli’s local state storage gives you access to a hash that is automatically persisted to disk when changes are made. Configuration You can configure it in config/storage.rb. local_state '/var/mytool/localstate', force_creation: true, halt_on_error: true There are three parameters to configure it with: The path as a string (self-explanatory) force_creation This will attempt to create the path and file if it does not exist (equivalent to an mkdir -p and touch in linux) halt_on_error RBCli’s default behavior is to raise an exception if the file can not be created, read, or updated at any point in time If this is set to false, RBCli will silence any errors pertaining to file access and will fall back to whatever data is available. User Configuration Files https://akhoury6.github.io/rbcli/advanced/user_config_files/ Thu, 20 Jun 2019 15:07:21 -0400 https://akhoury6.github.io/rbcli/advanced/user_config_files/ RBCli provides built-in support for creating and managing userspace configuration files. It does this through two chains: the defaults chain and the user chain. Defaults chain The defaults chain allows you to specify sane defaults for your CLI tool throughout your code. This gives you the ability to declare configuration alongside the code, and allows RBCli to generate a user config automatically given your defaults. There are two ways to set them: