Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: make main command easier to call. #71

Merged
merged 3 commits into from
May 5, 2023

Conversation

winder
Copy link
Contributor

@winder winder commented May 5, 2023

Summary

Move the main cobra command into a public cli package.

This makes it easier to embed in another program, see the main.go file for an example.
It also gives finer control over how plugins are selected, as the main function can choose to include or exclude imports.

Test Plan

Existing CI. This is a non functional change that pretty much just moves code around.

Example

In a sample project with a plugin stub, the following is a complete example to recreate the main function for testing:

package main

import (
	"fmt"
	"os"

	_ "github.com/algorand/conduit/conduit/plugins/exporters/all"
	_ "github.com/algorand/conduit/conduit/plugins/importers/all"
	_ "github.com/algorand/conduit/conduit/plugins/processors/all"
	_ "github.com/winder/conduit-test-plugin/plugin" // not published

	"github.com/algorand/conduit/pkg/cli"
)

func main() {
	conduitCmd := cli.MakeConduitCmdWithUtilities()
	if err := conduitCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}
	os.Exit(0)
}

go.mod

module github.com/winder/conduit-test-plugin

go 1.17

require (
	github.com/algorand/conduit v1.1.0
	github.com/algorand/go-algorand-sdk/v2 v2.0.0-20230324200319-055c8d2b174a
	github.com/sirupsen/logrus v1.8.1
	github.com/spf13/cobra v1.3.0 // indirect
	gopkg.in/yaml.v2 v2.4.0
)

// redirect to this branch
replace github.com/algorand/conduit => github.com/winder/conduit v0.0.0-20230505131953-c8c6d92fd0f9
> go run cmd/main.go list 
importers:
  algod       - Importer for fetching blocks from an algod REST API.
  file_reader - Importer for fetching blocks from files in a directory created by the 'file_writer' plugin.

processors:
  filter_processor - Filter transactions out of the results according to a configurable pattern.
  noop             - noop processor

exporters:
  file_writer - Exporter for writing data to a file.
  test_plugin - Local plugin included along with the others.
  noop        - noop exporter
  postgresql  - Exporter for writing data to a postgresql instance.

@winder winder marked this pull request as ready for review May 5, 2023 13:04
@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #71 (c8c6d92) into master (442791a) will increase coverage by 0.84%.
The diff coverage is 73.46%.

@@            Coverage Diff             @@
##           master      #71      +/-   ##
==========================================
+ Coverage   67.66%   68.50%   +0.84%     
==========================================
  Files          32       36       +4     
  Lines        1976     2388     +412     
==========================================
+ Hits         1337     1636     +299     
- Misses        570      660      +90     
- Partials       69       92      +23     
Impacted Files Coverage Δ
conduit/data/block_export_data.go 100.00% <ø> (+92.30%) ⬆️
conduit/plugins/importers/algod/metrics.go 100.00% <ø> (ø)
pkg/cli/internal/list/list.go 20.75% <ø> (ø)
...lugins/exporters/postgresql/postgresql_exporter.go 66.66% <51.21%> (-11.54%) ⬇️
pkg/cli/cli.go 65.97% <65.97%> (ø)
conduit/pipeline/pipeline.go 66.09% <72.10%> (+0.64%) ⬆️
conduit/data/config.go 76.47% <76.47%> (ø)
conduit/plugins/importers/algod/algod_importer.go 84.69% <88.17%> (-3.62%) ⬇️
conduit/pipeline/errors.go 100.00% <100.00%> (ø)
pkg/cli/internal/initialize/init.go 75.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified by building the conduit binary and checking its version command.

@winder winder merged commit 79fb4fd into algorand:master May 5, 2023
@winder winder deleted the will/cli-package branch May 5, 2023 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants