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

Basic Cirrus CLI with validate command #1

Merged
merged 7 commits into from
Jul 13, 2020
Merged

Basic Cirrus CLI with validate command #1

merged 7 commits into from
Jul 13, 2020

Conversation

edigaryev
Copy link
Contributor

Let's roll.

Copy link
Contributor

@fkorotkov fkorotkov left a comment

Choose a reason for hiding this comment

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

Let's also change the file structure since we are planning to open source Cirrus agent in the repo as well. So let's put all the CLI related stuff in cli folder and all the agent stuff in agent folder. All the common sources we can leave in pkg folder.

How about mocing:

  • cmd/cirrus/main.go to cli/cmd.go
  • internal/cmd/root.go to cli/internal/root.go
  • internal/cmd/validate.go to cli/internal/commands/validate.go
  • internal/cmd/validate_test.go to cli/internal/commands/validate_test.go

task:
container:
image: golangci/golangci-lint:latest
name: Lint
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the annotations here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 16007e1.

ErrTransport = errors.New("transport error")
)

type Parser struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd call it GraphQLValidator since it's not actually parsing. The upcoming GRPC endpoint will be parsing indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it still does some parsing behind the scenes, right? Otherwise it'd be impossible to fill the Errors field in the Result struct.

The idea here is to abstract away GraphQL-related bits as much as possible since we already know that in the near future it will be superseded by a gRPC endpoint.

This allows us to keep the API intact while it undergoes internal changes, except for the GraphqlEndpoint field, but the only reason an API consumer might want to set this field is tests.

You still sure it'd make a difference?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, with replacing it with GRPC I don't mind to live it as Parser here.

}

func absolutize(file string) string {
return filepath.Join("..", "..", "test", "fixtures", "parser", file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's maybe move the files to testdata folder? Saw it here that it's a convetion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 0b70a4a.

@edigaryev
Copy link
Contributor Author

edigaryev commented Jul 13, 2020

cmd/cirrus/main.go to cli/cmd.go
internal/cmd/root.go to cli/internal/root.go

This would cause the go install github.com/cirruslabs/cirrus-cli/... to produce a cli binary in $GOPATH/bin, but we want it to be cirrus, right?

See https://tip.golang.org/cmd/go/#hdr-Compile_packages_and_dependencies:

When compiling a single main package, build writes the resulting executable to an output file named after the first source file ('go build ed.go rx.go' writes 'ed' or 'ed.exe') or the source code directory ('go build unix/sam' writes 'sam' or 'sam.exe'). The '.exe' suffix is added when writing a Windows executable.

Also, the cmd convention serves as a great signifier of where the program's entrypoints are actually are, which eases the understanding of the codebase.

internal/cmd/validate.go to cli/internal/commands/validate.go
internal/cmd/validate_test.go to cli/internal/commands/validate_test.go

See ad7efdc.

@edigaryev edigaryev requested a review from fkorotkov July 13, 2020 10:09
@fkorotkov
Copy link
Contributor

Should we then put the agent in a separate repo as well? I was debating about that this weekend 🤔 I'm a fan of having everything in one repo, but I also see the point that the agent will not change as frequently, plus having it in separate repositories will force us to make backward compatible changes which is good for Cirrus CI as a distributed executor.

Copy link
Contributor

@fkorotkov fkorotkov left a comment

Choose a reason for hiding this comment

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

My understanding of testdata was that it doesn't live in the root but rather next to a package it is needed for. Like pkg/parser/testdata 🤔

ErrTransport = errors.New("transport error")
)

type Parser struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, with replacing it with GRPC I don't mind to live it as Parser here.

@edigaryev
Copy link
Contributor Author

Should we then put the agent in a separate repo as well? I was debating about that this weekend 🤔 I'm a fan of having everything in one repo, but I also see the point that the agent will not change as frequently, plus having it in separate repositories will force us to make backward compatible changes which is good for Cirrus CI as a distributed executor.

I don't see how the agent's slow rate of change makes it a bad target for inclusion. Does it have something to do with compilation times?

How about we keep the agent where it is right now, and as we progress towards a less "thin" CLI we'll see the overlap more clearly, and adapt accordingly?

@fkorotkov
Copy link
Contributor

Let's discuss offline today. 🤔

@edigaryev
Copy link
Contributor Author

My understanding of testdata was that it doesn't live in the root but rather next to a package it is needed for. Like pkg/parser/testdata 🤔

Thought these files might be useful for other packages in the future, but the way you described it makes more sense now, see 759b054.

@fkorotkov fkorotkov merged commit ae9641b into master Jul 13, 2020
@fkorotkov fkorotkov deleted the validate branch July 13, 2020 13:27
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