Testing cli tool with logging

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SonarQube - Static code analysis for 29 languages.
  • talent.io - Download talent.io’s Tech Salary Report
  • Scout APM - Truly a developer’s best friend
  • cobra

    A Commander for modern Go CLI interactions

    and probably something else will be added in the future. The final kind of launch command would like to see such djob [options] - command. Command is the command (with arguments to run). -- should separate the arguments of the utility from the arguments of the program to run. There are several excellent solutions for working with command-line arguments, such as spf13/cobra or urfave/cli. But they’re good for building an interface out of a lot of commands, and for one (as in my example) they’re redundant. So I used the flag library. I have defined the following structure with arguments:

  • urfave/cli

    A simple, fast, and fun package for building command line apps in Go (by urfave)

    and probably something else will be added in the future. The final kind of launch command would like to see such djob [options] - command. Command is the command (with arguments to run). -- should separate the arguments of the utility from the arguments of the program to run. There are several excellent solutions for working with command-line arguments, such as spf13/cobra or urfave/cli. But they’re good for building an interface out of a lot of commands, and for one (as in my example) they’re redundant. So I used the flag library. I have defined the following structure with arguments:

  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

  • logrus

    Structured, pluggable logging for Go.

    Before moving to testing I will talk about logging. Logging is another component that matters for testing implementation. In any case, it is required in almost any program, including the utility I describe. I used the library logrus, because it has the ability to intercept logs with hooks. And I used this feature to read logs during testing. At the same time, the code of the main function itself does not have to adapt to tests.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts