Fastlane set options auto value - fastlane

I would like to submit my lane with optional options. So for example the lane:
lane :mylane do |options|
mailgun(
to: "#{options[:mailto]}"
....
)
end
How do I give :mailto a default value? So if I would run fastlane mylane it would automatically set :mailto to mail#example.com.
But if I would runfastlane mylane mailto:"secondmail#example.com" it would use that value

As Lyndsey Ferguson pointed out in a comment on this answer, the following is simplest:
mail_addr = options.fetch(:mailto, 'mail#example.com')
where the first parameter of fetch is the option to fetch, and the second is the default value if the option was not passed in.
I just want to add that this works a lot better than the other suggestion:
options[:mailto] || 'mail#example.com'
when dealing with boolean options.
Fastlane (or maybe Ruby) interprets true, false, yes, and no as boolean values instead of strings (maybe others too, though I tried N, n, NO, and FALSE and they were treated as strings), so if in your lane implementation you had:
options[:my_option] || true
or
(options[:my_option] || 'true') == 'true'
you would get unexpected behaviour.
If you didn't pass in myOption at all, this would default to true as you would expect. If you passed in true this would also return true. But if you passed in false this would turn into true, which you of course wouldn't want.
Using options.fetch(:myOption, true) works great with boolean flags like the ones mentioned above and therefore seems better to use in general.
Here's a very thorough example in case you want to test it yourself:
lane :my_lane do |options|
puts("You passed in #{options[:my_option]}")
my_option = options[:my_option] || true
if my_option
puts('Using options[:my_option], the result is true')
else
puts('Using options[:my_option] the result is false')
end
my_option_fetched = options.fetch(:my_option, true)
if my_option_fetched
puts('Using fetched, the result is true')
else
puts('Using fetched, the result is false')
end
end
Outputs:
fastlane my_lane my_option:true
You passed in true
Using options[:my_option], the result is true
Using fetched, the result is true
fastlane my_lane my_option:false
You passed in false
Using options[:my_option], the result is true
Using fetched, the result is false
fastlane my_lane my_option:no
You passed in false
Using options[:my_option], the result is true
Using fetched, the result is false
Note, e.g. FALSE would default to true as it is not being interpreted as a boolean, which seems reasonable to me.
(Fastlane 1.77.0, Ruby 2.7.2)
EDIT: It's worth noting that if you pass an empty string instead of nothing/null you would not get the default value from the fetch method.

I'm not sure there's a way to make Fastlane pass a default. The processing is pretty simple:
https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/command_line_handler.rb#L10
But you can easily do this in your Fastfile:
lane :mylane do |options|
mail_addr = options[:mailto] || "mail#example.com"
mailgun(
to: "#{mail_addr}"
....
)
end

Related

agent cannot be resolved to a variable in function body but works in other blocks

I currently have a function that gets checked at certain time intervals. I want a hold to unblock upon satisfaction of the condition in the function body. However, agent can never be resolved to a variable, even though this convention of referring to the agent works in other process blocks. The agent that is present in the (((Patient)agent) is the agent that cannot be resolved to a variable. Patient is an agent type and has the variable isMorning that gets set to true or false upstream in the model. Below is the code in the function block, and the parameters are set to Just action (returns nothing). The (((Patient)agent) would be in a queue block prior to the hold.
if (((Patient)agent).isMorning == true && SurgeonMorning.idle() > 0){
hold.unblock();}
else if (((Patient)agent).isMorning == false && SurgeonAfternoon.idle() == 0){
hold.unblock();}
If this is code in a function, you need to provide a function argument and use that instead of agent.
In the properties of the function under arguments, add an entry myPatient and specify the type as Patient (right side from the dropdown).
Then, you can use the code as
if (myPatient.isMorning == true && SurgeonMorning.idle() > 0){
hold.unblock();}
else if (myPatient.isMorning == false && SurgeonAfternoon.idle() == 0){
hold.unblock();}
Check the help to understand functions more. And this article to understand when (and when not) you can use these little keywords like agent: https://www.benjamin-schumann.com/blog/2016/2/4/the-magic-lightbulb-and-how-it-can-help-your-anylogic-modelling

Swift 5 isEmoji method returns true for a number?

Like in example below isEmoji method returns true for a number :
let scalars: [Unicode.Scalar] = ["🤓", "+", "1"]
for s in scalars {
print(s, "-->", s.properties.isEmoji)
}
// 🤓 --> true
// + --> false
// 1 --> true... wait what? 😦
But why and how to determine for the last case in my example.
I make a little search after facing this issue and found the answer in Apple's documentation. I am sharing with you so that you do not waste your valuable time in the future:
The final result is true because the ASCII digits have non-default
emoji presentations; some platforms render these with an alternate
appearance.
Because of this behavior, testing isEmoji alone on a
single scalar is insufficient to determine if a unit of text is
rendered as an emoji; a correct test requires inspecting multiple
scalars in a Character. In addition to checking whether the base
scalar has isEmoji == true, you must also check its default
presentation (see isEmojiPresentation) and determine whether it is
followed by a variation selector that would modify the presentation.
This property corresponds to the “Emoji” property in the Unicode
Standard.
SOLUTION
So you can check like the line below:
let scalars: [Unicode.Scalar] = ["🤓", "+", "1"]
for s in scalars {
print(s, "-->", (s.properties.isEmoji && s.properties.isEmojiPresentation))
}
// 🤓 --> true
// + --> false
// 1 --> false

How to use Optional in Netlogo Extensions

I want to create a netlogo primitive that may receive a boolean or may not. Therefore I want make possible to the user that he uses the primitive of these two ways:
1:
ask Walkers [
qlearningextension:learning
]
2:
ask Walkers [
qlearningextension:learning true
]
I tried to do that with OptionalType, but I could not make it. Is it possible to do what I want? If so, how can I do it?
So OptionalType unfortunately only works with CommandBlockType. For a good example of how that works, check out the sample-scala extension (maybe that's where you saw a reference to it in the first pace). OptionalType will not work with BooleanType.
There is a secondary option, that's a little hacky. You can use RepeatableType along with setting defaultOption and minimumOption in your syntax (so NetLogo knows that 0 arguments is okay/expected). Scala code example:
object RepeatableTypeTest extends api.Command {
override def getSyntax =
commandSyntax(
right = List(BooleanType | RepeatableType),
defaultOption = Some(0),
minimumOption = Some(0)
)
def perform(args: Array[api.Argument], context: api.Context) {
println(args.length)
if (args.length > 0) {
val ref = args(0).getBoolean
println(ref)
} else {
println("No argument given!")
}
}
}
Then you just have to wrap calls with the boolean argument in parenthesis, so NetLogo knows you're not starting a new command (it expects the defaultOption without the parens):
to test
sample-scala:rep-bool
(sample-scala:rep-bool true)
(sample-scala:rep-bool false)
(sample-scala:rep-bool false true false true false)
end
The problem with this, as you can see in the example, is if your users want to they can provide extra useless booleans: (sample-scala:rep-bool false true false false true false false). If your code ignores them they won't have an effect, but they could be confusing or weird to extension users.

In Crystal Reports, boolean parameter to select both true and false

Using CR 2008.
I have a Boolean parameter with true and false values which works fine. Is there a way to add a third option to show both such as 'True, False, Show All'?
Without setting the parameter to allow multiple values. I.e. By setting the parameter to allow multiple values I can then just select both true and false. Not what I want - I want 3 single options as mentioned above.
Thanks in advance.
Create a String parameter.
Assume a convention.
Create a formula:
if {?MyParameter} = "True" then
//do stuff like when was true
else if {?MyParameter} = "False" then
//do stuff like when was false
else
//do new stuff: not true, not false

How can i change switchButton's value in smartface?

I am getting true or false value from database and I want to change the switchButton's sitation by looking this value.
I have a code as below but it doesn't work.
x[0].childNodes[0].nodeValue can be True or False and
if (x[0].childNodes[0].nodeValue) switchButton1.checked;
The switchButton's checked variable has to be defined in order to change it. Like: switchButton.checked = true;
Hope that helps! :)