Exercise: Capturing and Parsing Command Output

Test your coding skills on controlling processes.


In this exercise, your challenge is to expand the goci tool that we developed previously to capture and parse the output of an additional command execution.

Problem Statement

Gocyclo is a tool that calculates relative complexity in Go functions. Functions that score higher might be good candidates for refactoring as they’re harder to understand and require more test cases to cover all scenarios.

In this exercise, you’ll improve the goci tool by adding a new step to the pipeline to execute the Gocyclo tool. Then you’ll capture and parse its output to decide whether to proceed or stop the pipeline.

Coding Challenge

Improve the goci tool you developed by adding an additional step to run Gocyclo. Gocyclo has several options to display different results. For this exercise, your goal is to run Gocyclo with the -avg option to display an average complexity for all functions in your project. Then, capture and parse the output, comparing it with a predefined threshold. If the average complexity for your project exceeds that threshold, the pipeline should stop. Otherwise it should continue to the next step.

Your new step should run Gocyclo with these options:

Get hands-on with 1200+ tech skills courses.