{"id":65557,"date":"2022-07-06T09:01:07","date_gmt":"2022-07-06T09:01:07","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=65557"},"modified":"2022-07-06T09:01:07","modified_gmt":"2022-07-06T09:01:07","slug":"3-steps-to-create-an-awesome-ux-in-a-cli-application","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=65557","title":{"rendered":"3 steps to create an awesome UX in a CLI application"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">3 steps to create an awesome UX in a CLI application<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/noaa-barki\" class=\"username\">Noaa Barki<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Wed, 07\/06\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-70086\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>As I was sitting in a meeting room, speaking with one of my teammates, our manager walked in with the rest of the dev team. The door slammed shut and our manager revealed that he had a big announcement. What unfolded before our eyes was the next project we were going to develop\u2014an open source CLI (command line interface) application.<\/p>\n<p>In this article, I&#8217;d like to share what I learned during our development process, and specifically what I wish I had known before we began developing <a href=\"https:\/\/www.datree.io\/\" target=\"_blank\" rel=\"noopener\">Datree&#8217;s CLI<\/a>. Perhaps the next person can use these tips to create a great CLI application faster.<\/p>\n<p>My name is Noaa Barki. I&#8217;ve been a full-stack developer for over six years, and I&#8217;ll let you in on a little secret\u2014I have a superpower: My interest and expertise are evenly split between back-end and front-end development. I simply cannot choose one without the other.<\/p>\n<p>So when my manager revealed the news about our future CLI, the back-end developer-me got very excited because I&#8217;d never created a CLI (or any open source project, for that matter). A few seconds later, the front-end developer-me started to wonder, <em>How can I build an awesome user experience in a CLI application?<\/em><\/p>\n<p>Since Datree CLI helps engineers prevent <a href=\"https:\/\/opensource.com\/article\/22\/4\/kubernetes-policies-config-datree\" target=\"_blank\" rel=\"noopener\">Kubernetes misconfigurations<\/a>, my users are primarily DevOps and engineers, so I interviewed all my DevOps friends and searched online about the general DevOps persona.<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">More great content<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/www.redhat.com\/en\/services\/training\/rh024-red-hat-linux-technical-overview?intcmp=7016000000127cYAAQ\">Free online course: RHEL technical overview<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/advanced-linux-commands\/?intcmp=7016000000127cYAAQ\">Learn advanced Linux commands<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheets?intcmp=7016000000127cYAAQ\">Download cheat sheets<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/linux?intcmp=7016000000127cYAAQ\">Find an open source alternative<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/resources?intcmp=7016000000127cYAAQ\">Explore open source resources<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<p>Here are the steps I came up with:<\/p>\n<ol>\n<li>Design the commands<\/li>\n<li>Design the UI<\/li>\n<li>Provide backward compatibility<\/li>\n<\/ol>\n<h2>Step 1: Design the commands<\/h2>\n<p>Once you have completed the strategic process, it&#8217;s time to design the commands. I think about CLI applications like magic boxes\u2014they hold great features that work in a magical way, but only if you know how to use them. That means a CLI application must be intuitive and easy to use.<\/p>\n<h3>My top six principles for CLI commands<\/h3>\n<p>Here are my top six principles and best practices for designing and developing CLI commands:<\/p>\n<p><strong>1. Input flag vs. arguments<\/strong><\/p>\n<p>Use arguments for required fields, and for everything else, use flags. Take, for example, the <code>datree test<\/code> command, which prints the policy results, and say that you want to enable the user to print the output into a specific file. If you use <code>datree test {pattern} {output-file}<\/code>, it is difficult to understand from reading the executed command which argument is the pattern and which argument is the file path.<\/p>\n<p>For example, this occurs with the following command: <code>datree test **\/* **.YAML<\/code>. However, if you use <code>datree test {pattern} -output {output-path}<\/code>, it becomes much clearer.<\/p>\n<p><strong>Note:<\/strong> Reports show that most users find flags to be clearer.<\/p>\n<p><strong>2. Enum-style vs. Boolean flags<\/strong><\/p>\n<p>It&#8217;s preferable to use an enum-style flag over a Boolean-style flag because then you (a developer and user) need to think about all combinations of the presence or absence of the flags in the command. An enum-style flag is a flag that assumes a value. Enum-style flags make it much easier to implement tab completion.<\/p>\n<p><strong>3. Use familiar language<\/strong><\/p>\n<p>Remember that a CLI is built more for humans than machines. Pick real-world language for your commands and descriptions.<\/p>\n<p><strong>4. Naming conventions<\/strong><\/p>\n<p>Use CLI commands that are named in a SINGLE form and VERB-NOUN format. This allows the command to be read like an imperative or request, for example: <em>Computer, start app!<\/em><\/p>\n<p>Minimize with the total number of commands you use, and don&#8217;t rush to introduce new verbs to new commands. This makes it easier for users to remember command names.<\/p>\n<p><strong>5. Prompts<\/strong><\/p>\n<p>Provide a bypass to the prompt option. The user cannot script the command if prompting is required to complete it. To avoid frustrating users, a simple <code>--output<\/code> flag can be a valuable solution to allow the user to parse the output and script the CLI.<\/p>\n<p><strong>6. Command descriptions<\/strong><\/p>\n<p>The root command should list all the commands with their descriptions. Provide a command description to all commands (or do not offer descriptions at all), choose the screen width you want it to fit into (generally an 80-character width), and begin with a lowercase character. Also, don&#8217;t end with a period to avoid unclear line breaks or lost periods.<\/p>\n<h2>Step 2: Design the UI<\/h2>\n<p>Now you have a solid definition for your users. You have also planned and designed your commands and outputs. Next it&#8217;s time to think about making the CLI application aesthetic, accessible, and easy to learn.<\/p>\n<p>If you think about it, almost every app must deal with UX (user experience) challenges during the users&#8217; onboarding and journey. The <em>how<\/em> part of UX for web applications is much more obvious because you have many component libraries (such as material-UI and bootstrap) that make it easier to adopt standard style guides and functionality flows. But what about CLI applications? Are there any design conventions for CLI interfaces? How can you create an aesthetic design of the CLI functionality that is also accessible? Is there any way to make the CLI UI as friendly as a GUI?<\/p>\n<h3>Top three UI and UX best practices for CLI applications<\/h3>\n<p><strong>1. Use colors<\/strong><\/p>\n<p>Colors are a great way to attract your user&#8217;s eyes and help them read commands and outputs much faster. The most recommended font colors are magenta, cyan, blue, green, and gray, but don&#8217;t forget that background colors can provide more variety. I encourage you to use yellow and red colors but remember that these are typically saved for errors and warnings.<\/p>\n<p><strong>2. Input-output consistency<\/strong><\/p>\n<p>Be consistent with inputs and outputs across the application; this encourages usability and allows the user to learn how to interact with new commands quickly.<\/p>\n<p><strong>3. Ordering arguments<\/strong><\/p>\n<p>Choose an argument&#8217;s position based on how it correlates with the command&#8217;s action. Consider NestJS&#8217;s generate command <code>nest generate {schematic} {name}<\/code>, which needs <em>schematic<\/em> and <em>name<\/em> as arguments. Notice that the action <em>generate<\/em> refers directly to the <em>schematic<\/em>, not <em>name<\/em>, so it makes more sense for <em>schematic<\/em> to be the first arg.<\/p>\n<h2>Step 3: Provide backward compatibility<\/h2>\n<p>Avoid modifying the output. Now that you know how to create a perfect CLI application, don&#8217;t forget to keep your users in the back of your mind, especially when enabling scripting the CLI. Remember that any change in the command&#8217;s outputs may break users&#8217; current scripts; therefore, avoid modifying the output.<\/p>\n<h2>Wrap up<\/h2>\n<p>Creating a new CLI is exciting and challenging, and doing so with a helpful and easy UX adds to the challenge. My experience shows that three key factors go into a successful UX for a CLI project:<\/p>\n<ol>\n<li>Design the commands<\/li>\n<li>Design the UI<\/li>\n<li>Provide backward compatibility<\/li>\n<\/ol>\n<p>Each of these phases has its own components that support the logic and make the lives of your users easier.<\/p>\n<p>I hope these concepts are useful and that you have the opportunity to apply them in your next project.<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Here is what I&#8217;ve learned to be the key factors that go into a successful user experience for a CLI project.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/07\/lenovo-thinkpad-laptop-concentration-focus-windows-office.png\" width=\"799\" height=\"447\" alt=\"Business woman on laptop sitting in front of window\" title=\"Woman using laptop concentrating\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Image by Mapbox Uncharted ERG,\u00a0<a href=\"https:\/\/creativecommons.org\/licenses\/by\/3.0\/us\/\" rel=\"noreferrer nofollow noopener\" target=\"_blank\">CC-BY 3.0 US<\/a><\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/command-line\" hreflang=\"en\">Command line<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/devops\" hreflang=\"en\">DevOps<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/art-and-design\" hreflang=\"en\">Art and design<\/a><\/div>\n<\/p><\/div>\n<div class=\"hidden field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/07\/cc-by-sa-4-3.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>3 steps to create an awesome UX in a CLI application Noaa Barki Wed, 07\/06\/2022 &#8211; 03:00 Register or Login to like Register or Login to like As I was sitting in a meeting room, speaking with one of my teammates, our manager walked in with the rest of the dev team. The door slammed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":65558,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-65557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/65557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65557"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/65557\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/65558"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}