Skip to content

Pass context to own commands and profile runner#280

Merged
creativeprojects merged 5 commits intomasterfrom
pass-context-struct
Nov 11, 2023
Merged

Pass context to own commands and profile runner#280
creativeprojects merged 5 commits intomasterfrom
pass-context-struct

Conversation

@creativeprojects
Copy link
Owner

@creativeprojects creativeprojects commented Nov 1, 2023

  • introduction of a Context struct to pass context information around commands and profiles.
  • own commands can return a specific error to exit main with an error code (will be used by run-schedule)
  • extract bits of code into methods to simplify main
  • add a pre field to ownCommand so commands can check the context before running

That will simplify future work like #259 and #146

@codecov
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Comparison is base (1b3292c) 77.48% compared to head (f650dd4) 77.82%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   77.48%   77.82%   +0.34%     
==========================================
  Files          97       99       +2     
  Lines       10283    10345      +62     
==========================================
+ Hits         7967     8050      +83     
+ Misses       2037     2014      -23     
- Partials      279      281       +2     
Flag Coverage Δ
unittests 77.82% <76.43%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
context.go 100.00% <100.00%> (ø)
own_command_error.go 100.00% <100.00%> (ø)
own_commands.go 100.00% <100.00%> (ø)
wrapper.go 87.20% <100.00%> (+0.10%) ⬆️
commands_display.go 48.57% <41.67%> (+8.13%) ⬆️
commands.go 53.68% <34.48%> (ø)

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@creativeprojects creativeprojects changed the title Pass context to own commands and profile runnner Pass context to own commands and profile runner Nov 1, 2023
creativeprojects added a commit that referenced this pull request Nov 2, 2023
Copy link
Collaborator

@jkellerer jkellerer left a comment

Choose a reason for hiding this comment

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

Like the change. Just have a few comments on the structs.

@creativeprojects
Copy link
Owner Author

I've implemented your comments (just because it made sense 😆 )

I've also added a method loadContext which... I'm not too sure about it.
The problem is that we need to load many things before we can setup the logger. In case of run-schedule command we need to access schedule-log.

So that's why I moved the log target to the loadContext as well 😐

@jkellerer
Copy link
Collaborator

I’ll also think about the log part and cross check it with the other PR.

creativeprojects added a commit that referenced this pull request Nov 5, 2023
@jkellerer
Copy link
Collaborator

jkellerer commented Nov 11, 2023

Setup logging in context creation actually makes sense since the log target can change (however can't seem to find it in this PR).

The only concern I have is that all the With... funcs should return a copy of the context so that side effects are avoided (and that all of the funcs behave the same). Copy is cheap and easy anyway. E.g. I'd not code if so verbose as in 552f4751 R60 because you need to read it all to know what is different. Would be easier to make a copy of the struct and only set what needs changing.

@creativeprojects
Copy link
Owner Author

Setup logging in context creation actually makes sense since the log target can change (however can't seem to find it in this PR).

It's creating logTarget in the loadContext method. The only choice at that point is from global or flags.

The rest is on the following PR actually. I thought that was enough changes for this one already:

To set the log from schedule, it's part of the pre callback (of run-schedule command)

https://github.com/creativeprojects/resticprofile/blob/run-schedule/commands.go#L614

@jkellerer
Copy link
Collaborator

LGTM

@creativeprojects
Copy link
Owner Author

Thanks 😉

@creativeprojects creativeprojects merged commit ae9554a into master Nov 11, 2023
@creativeprojects creativeprojects deleted the pass-context-struct branch November 11, 2023 19:31
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