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

Allow passing arguments as options after the -- option #616

Merged
merged 1 commit into from Jul 5, 2017
Merged

Allow passing arguments as options after the -- option #616

merged 1 commit into from Jul 5, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 7, 2017

root macro.C -- arg1 arg2 arg3 ... will behave as root macro.C(arg1,arg2,arg3,...).

Options won't be attached to:

  • expressions — root -e expression;
  • macros, passed with options (with ( in them, to be precise) — root macro.C(arg1, arg2);
  • .root files;

If there are several macros without options, the arguments will be passed to the last one (with warning).
If there are no macros, the options after the -- will be ignored (with warning).

No options description was updated yet.

Initially my idea was to allow to turn macro function parameters into named options, but @Axel-Naumann asked to leave them positional. But I'm still planning to introduce named arguments/options. Positional arguments as options is not a great improvement over the current way to pass arguments to macros.

@phsft-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@Axel-Naumann Axel-Naumann self-assigned this Jun 7, 2017
Copy link
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for coding this! Do my (tiny) comments make sense?

continue;

if (macro)
Warning("GetOptions", "-- is used with several macroses. "
Copy link
Member

Choose a reason for hiding this comment

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

Spelling: two times a macro is two "macros" :-)

Copy link
Member

Choose a reason for hiding this comment

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

Anything that's not a merge commit is perfectly fine: amend, rebase, add commits - whatever works for you!

continue;
if (file->String().EndsWith(".root"))
continue;
if (strchr(file->String().Data(), '('))
Copy link
Member

Choose a reason for hiding this comment

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

Don't we have a TString function which can replace the strchr? Like Index() or something?

@@ -468,7 +468,46 @@ void TApplication::GetOptions(Int_t *argc, char **argv)
} else {
Warning("GetOptions", "-e must be followed by an expression.");
}
} else if (!strcmp(argv[i], "--")) {
TObjString* macro = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Can you use nullptr instead of NULL? (I know, not obvious when looking at surrounding code...)

}

if (macro) {
argv[i] = null;
Copy link
Member

Choose a reason for hiding this comment

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

Should this null be nullptr?

Copy link
Author

Choose a reason for hiding this comment

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

No, it shoud not, because later options participate in strcmp ([1]), which doesn't like null pointers. null is defined as "".

[1] https://github.com/BerserkerTroll/root/blob/385d7c5f7196c9b47f8dbc6d126bc6cd079d7dec/core/base/src/TApplication.cxx#L592

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, indeed, you're right!

@Axel-Naumann
Copy link
Member

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

Starting build on gcc49/centos7, native/mac1012, gcc49/slc6, gcc62/slc6, native/ubuntu14 with CMake flags -Dvc=OFF -Dimt=ON -Dccache=ON

str += ',';
argv[i] = null;
}
str.EndsWith(",") ? str[str.Length()-1] = ')' : str += ')';
Copy link
Member

@Axel-Naumann Axel-Naumann Jun 7, 2017

Choose a reason for hiding this comment

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

Except for adding spaces around the "-" in Length() - 1, I don't think clang-format's suggestions are of much value. So please ignore its "failure".

@ghost ghost mentioned this pull request Jun 12, 2017
Copy link
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

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

Could you fix this tiny remaining issue?

TObjString* macro = nullptr;

if (fFiles) {
for (auto f = fFiles->GetEntriesFast(); f --> 0; ) {
Copy link
Member

Choose a reason for hiding this comment

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

Ha! Funny syntax :-) Nonetheless - could you reword this to the more common (for ROOT)

for (auto f: *fFiles)

}

if (macro) {
argv[i] = null;
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, indeed, you're right!

@Axel-Naumann
Copy link
Member

Could you (in a separate PR) hand in a test for this wonderful feature to the roottest repo?

Could you also add a few lines about this to README/ReleaseNotes/v612/index.md?

@pcanal
Copy link
Member

pcanal commented Jun 21, 2017

We still also need some documentation for it (similar to the PR description at least).

@Axel-Naumann
Copy link
Member

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

Starting build on gcc49/centos7, native/mac1012, gcc49/slc6, gcc62/slc6, native/ubuntu14 with flags -Dvc=OFF -Dimt=ON -Dccache=ON
How to customize builds

@Axel-Naumann
Copy link
Member

We seem to have two successful builds versus three infrastructure failures - so I suppose that's "green". Merging - thank you for your contribution!

@Axel-Naumann Axel-Naumann merged commit 0cd8468 into root-project:master Jul 5, 2017
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