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.
-
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.3
to4.0.0
and I hit the following compile time issues::NoSuchOptions.givenName
renamed toparamName
CliktHelpFormatter
replaced withMordantHelpFormatter
localization
constructor parameter.width
constructor parameter.maxWidth
constructor parameter.context
constructor parameter.formatHelp()
- takes an additional first argument which isUsageError?
.renderArgument
- replaced withrenderArguments
or maybestyleArgumentName
.renderHelpText
- gone.renderOptionName
- gone, possibly replaced withstyleOptionName
.renderSubcommandName
- gone, possibly replaced withstyleSubcommandName
.ContextBuilder
console
- needed to interceptstdout
andstderr
.helpFormatter
- changed fromHelpFormatter?
to((Context) -> HelpFormatter)?
.PrintHelpMessage
command: CliktCommand
gone, presumably replaced withcontext?.command
which isCliktCommand?
.PrintMessage.error
appears to have been renamed toprintError
.UsageError.helpMessage()
gone, might have been replaced withmessage
orformatMessage
is unclear but probably the first.Option
val optionHelp
becameoptionHelp(Context)
.provideDelegate
changed parameter name fromprop
toproperty
.CliktCommand.commandHelp
val 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.stdout
andstderr
, it looks as though the code directly callsSystem.err
(and maybeSystem.out
) and I can't use those to intercept what previously went to theconsole
as 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.5
to handle renames or replacing properties with functions that take aContext
, e.g.Option.optionHelp(Context)
as an alias forOption.optionHelp
.NoSuchOptions.givenName
toparamName
, it will require a change to upgrade to3.5.5
but it will be one less change to make when going to4.0.1
.CliktCommand40
class to both3.5.5
and4.0.0
.3.5.5
and4.0.0
respectively.helpFormatter = contextAwareFormatter {...}
. On 3.5.5 that would create aHelpFormatter
that encapsulates the callingCliktCommand
and when called can retrievecommand.currentContext
and 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