Migrating from 3.5.3 to 4.0.0 #442
Replies: 2 comments 1 reply
-
|
Hi, thanks for taking the time to write this all up! As you've noticed, the Setting the widthcontext {
terminal = Terminal(width = myWidth)
}Intercepting stdoutIf you're just doing this for tests, 4.0 added the CliktCommand.test extension which handles capturing everything for you. You can also use it to set the width: If you need something more avanced, you can write your own |
Beta Was this translation helpful? Give feedback.
-
|
No problem. I needed to take a record for my own needs so it seemed to make sense to do it here just in case you found it useful. Another problem:
I've managed to get my code to almost compile with both 3.5.3 and 4.0.0 using a compatibility layer. The remaining issues are minor and should not be an issue. Rather than wait to do it properly I've hacked my way through to running with Clikt 4.0.0 just to see what the effect would be.
One of my hacks was to force a fixed column width. The problem with a dynamic column width per group is:
I had a look around and Mordant looks like you can specify widths for the columns in table layouts but I cannot get to the ones that Clikt uses. I was wondering if there's any way to get a fixed column width across all option groups? I'll probably be unresponsive for a week. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We recently, last few months, started using Clikt in https://cs.android.com/android/platform/superproject/+/master:tools/metalava/. Feel free to take a look and see how we hack it around to do all sorts of nasty things with help in order to try and get it to behave well with our existing non-Clikt options processor. Maybe it will give you some ideas for improvements you could make, or maybe you could point out improvements we could make.
BTW. Clikt is awesome. For all the pain (fun?) I have had trying to twist it to do things it was not designed to do, it has been a pleasure to use and saved me a lot of tedium.
I started looking at migrating https://cs.android.com/android/platform/superproject/+/master:tools/metalava/ from
3.5.3to4.0.0and I hit the following compile time issues::NoSuchOptions.givenNamerenamed toparamNameCliktHelpFormatterreplaced withMordantHelpFormatterlocalizationconstructor parameter.widthconstructor parameter.maxWidthconstructor parameter.contextconstructor parameter.formatHelp()- takes an additional first argument which isUsageError?.renderArgument- replaced withrenderArgumentsor maybestyleArgumentName.renderHelpText- gone.renderOptionName- gone, possibly replaced withstyleOptionName.renderSubcommandName- gone, possibly replaced withstyleSubcommandName.ContextBuilderconsole- needed to interceptstdoutandstderr.helpFormatter- changed fromHelpFormatter?to((Context) -> HelpFormatter)?.PrintHelpMessagecommand: CliktCommandgone, presumably replaced withcontext?.commandwhich isCliktCommand?.PrintMessage.errorappears to have been renamed toprintError.UsageError.helpMessage()gone, might have been replaced withmessageorformatMessageis unclear but probably the first.Optionval optionHelpbecameoptionHelp(Context).provideDelegatechanged parameter name fromproptoproperty.CliktCommand.commandHelpval replaced withcommandHelp(Context).Any advice/clarification on the appropriate mapping to use would be really helpful. Of particular concern is:
width,maxWidth- I have to be able to set a maximum width for the purposes of testing to match other non-Clikt help output that has not yet been migrated.stdoutandstderr, it looks as though the code directly callsSystem.err(and maybeSystem.out) and I can't use those to intercept what previously went to theconsoleas I need to be able to intercept both separately.What makes upgrading of anything tricky is the number of additional changes you have to make atomically with the upgrade. Any reductions in those makes the process a lot easier. Easier upgrades means less people left behind. It would be really helpful if you could provide support to aid in the migration. I was thinking along the lines of adding code to 3.5.5 and 4.0.1 to close the gap between them.
Some suggestions as to changes that would help:
3.5.5to handle renames or replacing properties with functions that take aContext, e.g.Option.optionHelp(Context)as an alias forOption.optionHelp.NoSuchOptions.givenNametoparamName, it will require a change to upgrade to3.5.5but it will be one less change to make when going to4.0.1.CliktCommand40class to both3.5.5and4.0.0.3.5.5and4.0.0respectively.helpFormatter = contextAwareFormatter {...}. On 3.5.5 that would create aHelpFormatterthat encapsulates the callingCliktCommandand when called can retrievecommand.currentContextand then pass that into the factory method. On 4.0.1 it would just return the factory lambda.I'm going to do something like that myself, so if you are interested then I am happy to work with you to contribute it to help anyone else dealing with similar issues.
I'll be AFK for a week so there is no rush.
Beta Was this translation helpful? Give feedback.
All reactions