-
Notifications
You must be signed in to change notification settings - Fork 49
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
Refactor CLI Projects to Single Entrypoint #476
Conversation
As of this commit: These still need a larger scope refactor due to a non standard options or calling pattern: Defog Detect Backdoor Detect Crypto Find Squats Metadata Also, even those implemented mostly need to return a proper error code isntead of void Task.
They now are part of the CLI lib
OctoKit dependency changed this field from int to long so updating model to match.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, these changes look good to me.
My personal preference would be to rename the LegacyRunAsync
methods to reflect what the method does. The RunAsync
method makes sense because it comes from the base class and must apply to all commands but there's no reason the LegacyRunAsync
methods can't be renamed to be more specific. It isn't worth holding the PR up over.
src/Shared.CLI/Tools/DownloadTool.cs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It appears that git
believes this is a new file rather than rename of oss-download/DownloadTool.cs
so we'll lose the history on it. (It is probably not worth going back through commit history to fix this.)
src/oss-gadget-cli/Program.cs
Outdated
using Microsoft.CST.OpenSource.OssGadget.Tools.HealthTool; | ||
using System.Reflection; | ||
|
||
class OssGadgetCli : OSSGadget |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it is more .NET idiomatic to have the class and filename match (i.e., class Program
in Program.cs
) which would move OssGadgetCli
to a separate file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed program.cs to ossgadgetcli.cs.
src/oss-gadget-cli/Program.cs
Outdated
{ | ||
var cli = new OssGadgetCli(); | ||
await cli.ExecuteAsync(args); | ||
return (int)cli._returnCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it is odd to use a field for a return value. We could refactor ExecuteAsync
(and the methods it calls) to return this value instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've simplified this.
I think the different verbs/options For example, "Calculate a risk metric for the given package" provides more information to the user than "Run risk calculator tool" Any help text that says, "runs the Foo tool" makes me ask "...but what does Foo tool do?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any impacts to Terrapin. I only skimmed things that weren't directly relevant to us - but in general this refactor looks great.
This PR mainly refactors the many CLI projects to a single entrypoint. From a CLI perspective they now can be accessed with verbs against a the single
oss-gadget-cli
binary. This also standardizes calling patterns for each tool using theBaseTool
class to aRunAsync
method which takes the appropriate type of options. If the project previously had aRunAsync
entrypoint with a different return type the old entrypoint was renamedLegacyRunAsync
. This refactor does not attempt to change execution behavior, merely to simplify project structure and publishing, specifically to enable publishing the single CLI binary to Nuget withotu having to manage many project publications.Also updates all dependencies.
Changes Model.User.Id field to long (from int) to match changes in OctoKit library which populates that field.
Marked as draft for feedback and refactor of build pipeline.