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

Better separation of binary and library #70

Merged
merged 17 commits into from
May 7, 2024
Merged

Conversation

Andriamanitra
Copy link
Owner

refactoring to get the library ready for 1.0 release (#28)

WIP

@Andriamanitra
Copy link
Owner Author

Andriamanitra commented May 1, 2024

edit: this is done now

Should we move OutputStyle and print_headers, print_statement, print_testcases, print_reverse_mode functions out of the library? They're very specific to the CLI and I don't think it's a good idea to commit to keeping them stable (we don't want to break the clashlib API when we tweak how the clashes are printed in the CLI tool).

@Andriamanitra
Copy link
Owner Author

Are there any more parts of main.rs that would make sense to provide as part of the clashlib API?

@Andriamanitra
Copy link
Owner Author

Andriamanitra commented May 1, 2024

What should the public API of solution look like? The current API is really weird (and basically undocumented). Maybe we should just hide the entire module until we can figure out a better API?

@Andriamanitra Andriamanitra force-pushed the separate-domain-logic branch from 6adabea to dd7e8d3 Compare May 1, 2024 11:08
@Andriamanitra
Copy link
Owner Author

Andriamanitra commented May 2, 2024

re: @ellnix (from #71)

I suggest

  • Moving App to lib
  • Moving all the helper functions (functions that do not have a corresponding command) into App
  • Removing the functions that have commands corresponding to them from App and just having them as regular functions in main.rs (or as part of a Cli type)
  • Making the App constructor to take a single package_name parameter: let app = App::new("dev.CoCtus.coctus");

This would then separate the responsibility between calling the commands and the helper functions which we could use in tests. It would also prepare for #61 by allowing configuration to be stored in App and be used by users of the lib.

I've given this some thought and I think that it would be better to expose a simpler API that is completely agnostic of the coctus CLI tool and its data/config (that means keeping App private as its only purpose is to hold references to the configuration directories). Users of the library should have the choice of using their own config/data if they want to be independent of coctus the command line tool.

There are probably some methods in App that do "too much" though. Ideally they would follow this recipe (limiting I/O to the edges of the app):

  1. Doing I/O (reading args, environment variables and files)
  2. Passing the data forward to pure, easy-to-test functions (which we may want to expose in lib)
  3. Doing I/O (printing the output / errors)

This was referenced May 2, 2024
@Andriamanitra Andriamanitra marked this pull request as ready for review May 7, 2024 11:54
@Andriamanitra Andriamanitra changed the title Move domain logic from main.rs to lib Better separation of binary and library May 7, 2024
@Andriamanitra Andriamanitra merged commit ced9db8 into main May 7, 2024
2 checks passed
@Andriamanitra Andriamanitra deleted the separate-domain-logic branch May 20, 2024 18:42
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