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

CLI package update 1 #2019

Merged
merged 9 commits into from
Jul 18, 2017
Merged

CLI package update 1 #2019

merged 9 commits into from
Jul 18, 2017

Conversation

cquinn
Copy link
Contributor

@cquinn cquinn commented Jul 8, 2017

Features added:

  • string_seq option and arg value type for repeated strings collected into a sequence.
  • Command fullname() to make it easier to match on command name.
  • Checking commands are leaves so that partial commands return syntax errors.

Other changes:

  • Tests for the above.
  • _ValueType is now a trait instead of a union. This makes it easier to delegate type specific work to one place, and makes value type more easily extended.
  • A few other cleanups, like the removal of redundant box modifiers on methods.

@SeanTAllen
Copy link
Member

This should have a CHANGELOG entry (or entries) for features added.

Can you do a short writeup of the changes and how they should be in release notes when this goes out? I don't think anyone but you is capabale of writing up those notes @cquinn. It would be good to get them recorded now.

else
return // error was expected
let cs = CommandSpec.leaf("min imal", "")
h.fail("expected error on bad command name" + cs.name())
Copy link
Member

Choose a reason for hiding this comment

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

You probably want to append : to your string literal here.

Otherwise the cs.name() bit is going to get printed squished up against the word "name" from the string literal when printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@@ -325,22 +343,66 @@ class val ArgSpec
_name + "[" + _typ.string() + "]" +
if not _required then "(=" + _default.string() + ")" else "" end

type _Value is (Bool | String | I64 | F64)
class _StringSeq is ReadSeq[String]
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a persistent data structure holding a sequence of strings. Have you thought about using Vec[String] from the collections/persistent package instead of rolling your own here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me give that a look. I started with this simple wrapper class to get a Stringable and a String sequence of some kind. But a persistent structure might make more sense given the way it has to be updated during parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I still need the wrapper class, but could replace the Array[String] with a Vec[String] to avoid the array copying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ss.append(ss1.strings)
strings = ss

fun string(): String =>
Copy link
Member

Choose a reason for hiding this comment

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

If you're aiming to fulfill the Stringable interface, this should be returning a String iso^, which should be possible if you remove the trn from your recover statement below (so that it recovers to iso 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.

Got it.

if str.size() > 1 then str.append(",") end
str.append(s)
end
str.append("]")
Copy link
Member

Choose a reason for hiding this comment

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

For each of these append calls where you're appending a single-character string, you could be pushing just the single character (as a U8) instead. For example: str.push(']')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@cquinn
Copy link
Contributor Author

cquinn commented Jul 8, 2017

@SeanTAllen I can certainly write up CHANGELOG entries. Can you point me to an example I can refer to?

@SeanTAllen
Copy link
Member

Check out the existing CHANGELOG entries. I'd say this PR is multiple entries.

@cquinn
Copy link
Contributor Author

cquinn commented Jul 10, 2017

@SeanTAllen I guess I/we never wrote up changelog entries for the CLI package at all. I can take a stab at that too. Should I just add an edit to CHANGELOG.md in this PR?

@SeanTAllen
Copy link
Member

Yes to CHANGELOG entries being part of this PR

@cquinn cquinn force-pushed the cli_package_update1 branch 2 times, most recently from 503db79 to 1aa3933 Compare July 11, 2017 03:10
@cquinn
Copy link
Contributor Author

cquinn commented Jul 11, 2017

I've added a CHANGELOG entry to the unreleased section for the whole CLI implementation in this and the initial PR.

@jemc
Copy link
Member

jemc commented Jul 11, 2017

@cquinn - I don't fully understand the semantics of the string_seq argument type yet, and that made me realize it doesn't seem to be documented anywhere. Is there somewhere in the cli package where we can document how each argument type works, including string_seq?

@cquinn
Copy link
Contributor Author

cquinn commented Jul 11, 2017

@jemc yes, I will take some time now to document the types and the package as a whole, and add that to this PR.

@cquinn
Copy link
Contributor Author

cquinn commented Jul 16, 2017

@jemc @SeanTAllen I have added more doc comments, and a big CHANELOG entry. I'm not sure if the CHANGELOG entry is too much and maybe I should pare it down.

@jemc
Copy link
Member

jemc commented Jul 17, 2017

Thanks for the extra docs, it's great!

Maybe I'm being obtuse, but I still don't really understand what the CLI args for a "string seq" are supposed to look like, though... 😕

@SeanTAllen
Copy link
Member

@cquinn changelog looks good to me.

@cquinn
Copy link
Contributor Author

cquinn commented Jul 17, 2017

@jemc I've added more doc comments. The idea behind a string_seq is that it is a repeated option or arg that produces a sequence of strings after parsing. It can be used, for example, to allow multiple filenames to be passed to a tool that read them.

The examples/commandline/main.pony uses a string_seq to echo all of the command line args.

@jemc
Copy link
Member

jemc commented Jul 17, 2017

If I have an Option of a string_seq type, how does that work with other args and options - where does the string sequence associated with the option stop?

@cquinn
Copy link
Contributor Author

cquinn commented Jul 17, 2017

With Options, the option prefix has to be used each time, like:
--file=f1 --file=f2 --file=f3 and the results are collected into one string_seq.
With Args, there is no way to indicate termination, so a string_seq Arg should be the last arg and will consume all remaining command line tokens.

Maybe I need to include this doc somewhere as a comment.

@jemc
Copy link
Member

jemc commented Jul 17, 2017

Got it. It makes sense now.

Yes, I'd definitely like to see that in the documentation, since I don't think I'm the only one who will have that question 👍.

@cquinn
Copy link
Contributor Author

cquinn commented Jul 18, 2017

@jemc How does it look now?

@jemc jemc merged commit 3fb8eec into ponylang:master Jul 18, 2017
@jemc
Copy link
Member

jemc commented Jul 18, 2017

Great, thanks.

@cquinn cquinn deleted the cli_package_update1 branch July 18, 2017 23:29
@cquinn cquinn restored the cli_package_update1 branch February 6, 2019 02:43
@cquinn cquinn deleted the cli_package_update1 branch February 25, 2019 00:25
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