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

Refactor CLI Projects to Single Entrypoint #476

Merged
merged 23 commits into from
Nov 19, 2024
Merged

Refactor CLI Projects to Single Entrypoint #476

merged 23 commits into from
Nov 19, 2024

Conversation

gfs
Copy link
Contributor

@gfs gfs commented Nov 12, 2024

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 the BaseTool class to a RunAsync method which takes the appropriate type of options. If the project previously had a RunAsync entrypoint with a different return type the old entrypoint was renamed LegacyRunAsync. 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.

gfs added 12 commits November 7, 2024 12:10
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
@gfs gfs requested review from pmalmsten and jpinz November 12, 2024 20:38
gfs added 3 commits November 12, 2024 12:41
OctoKit dependency changed this field from int to long so updating model to match.
@gfs
Copy link
Contributor Author

gfs commented Nov 12, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@danfiedler-msft danfiedler-msft left a 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.

Copy link
Contributor

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.)

using Microsoft.CST.OpenSource.OssGadget.Tools.HealthTool;
using System.Reflection;

class OssGadgetCli : OSSGadget
Copy link
Contributor

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.

Copy link
Contributor Author

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.

{
var cli = new OssGadgetCli();
await cli.ExecuteAsync(args);
return (int)cli._returnCode;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@danfiedler-msft
Copy link
Contributor

I think the different verbs/options HelpText should use the same text as the first Example.

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?"

@gfs gfs marked this pull request as ready for review November 19, 2024 21:01
@gfs gfs merged commit 6fec18b into main Nov 19, 2024
1 check passed
@gfs gfs deleted the gfs/Refactor3 branch November 19, 2024 21:03
Copy link
Contributor

@pmalmsten pmalmsten left a 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.

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.

3 participants