xmlstarlet how can I specify s specific class - xmlstarlet

This code successfully makes enabled="false for both lines below.
How can I change the following so enabled = false for only the second line?
xmlstarlet ed --inplace --update '//ResultCollector/#enabled' --value 'false' "${scriptLocation}"
<ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Simple Data Writer" enabled="true">
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">

XPath allows specifying a specific xml element by order of appearance inside its parent:
--update '//ResultCollector[2]/#enabled'
The above expression selects all ResultCollector elements that appear as second under their parent for processing.
More generally, chances are your application will be safer selecting elements by an embedded information (such as a tag value) instead of by order:
--update '//ResultCollector[#guiclass="ViewResultsFullVisualizer"]/#enabled'
If it suits you, the above expression selects for processing all ResultCollector elements whose tag guiclass is ViewResultsFullVisualizer. In your example this also causes only the second ResultCollector to be updated as well.

Related

Compare actual file with file at specific baseline

I'm using clearcase 8.0.1.17, I want to compare a file in my wiew and his version at a specific baseline.
I can open version tree and see my baseline but I want to do that with command line.
My purpose is to do something like :
> myScript.sh file.c baseline
This will open bcompare and compare my actual file vs the version baseline
How can I do that ?
I can do :
> cleartool lsvtree myfile | grep myBaseline
But is there is no changes at myBaline it doesn't work.
First, make sure to try that in a dynamic view
Then check out the concept of version extended path: using a pathname_ccase syntax, you can add characters to the end of a relative or full path name, turning it into a VOB-extended path name.
VOB-extended path names that specify versions of elements are the most commonly used; they are called version-extended path names.
/vobs/proj/foo.c##/main/motif/4
That means you can:
find the version of the file with as label the Baseline name: see "How to search files by label"
compare that extended path name with the one currently visible in your view.
The idea is: in a dynamic view, you can access (read the content of) any version of a file through the extended pathname.
Which means you can execute bcompare on those contents (the one with the extended path, and the one currently visible in your view)
Of course, if this is an incremental baseline (instead of full), you might need a cleartool chbl -full to convert it to a full baseline, applying the UCM associated label to all files.
If you do a cleartool describe baseline:mybaseline#\myvobtag you will probably find that your baseline is an incremental baseline. Incremental baselines do not have a label on the version if it was changed in a prior baseline and not the current one...
cleartool diffbl -versions {baseline} {current stream} | grep {filename} can be used to find the version of the target file that is in the baseline, which you can use to do the compare...

ZSH avoid adding empty commands to history?

In zsh (with oh-my-zsh, is that matters) when I enter empty commands (e.g. just press enter) I see empty lines added to my ~/.zsh_history:
: 1508496422:0;ls
: 1508496422:0;vim
: 1508496482:0;
: 1508496482:0;
: 1508496482:0;
: 1508496482:0;
: 1508496490:0;
: 1508496490:0;
: 1508496490:0;
: 1508496490:0;
: 1508496494:0;ls
I'm wondering if it's possible to avoid adding these lines. I checked http://zsh.sourceforge.net/Doc/Release/Options.html but no luck. The reason why I'm trying to avoid adding empty lines is I'm using fzf and fzf lists these empty commands when I search in last commands in a directory.
If this is not possible in zsh side I'll try to search for a solution in fzf side.
There are a few Zsh settings to control what goes into your history
(though I'm surprised emtpies end up there; I can't reproduce that
despite also using fzf and hitting blank RETs a lot).
The man page for zshoptions(1) describes:
HIST_IGNORE_[ALL_]DUPS — This should at least reduce your
consecutive multiple empties down to one.
HIST_IGNORE_SPACE — Your empties might be treated as whitespace
and thus be eliminated. I like this feature anyway for intentionall
discarding commands by starting them with a space.
There is also the HISTORY_IGNORE option (not to be confused with
Bash's HISTIGNORE) — described in zshparam(1) with an example —
which lets you remove a set of patterns. An empty pattern may fix
your case. It also has a zshaddhistory hook that you could use to
more finely control exactly what goes into history.

Setting an attribute in a Nokogiri::XML::NodeSet with css

I was trying to set an attribute for a specific element in an xml file and I was having success using
doc.css('Object').attr("Id").value = timestamp
This was fine until the situation where 'Object' doesn't exist causing an exception in the program and quitting. To avoid that I wanted to use Nodeset as it'll just be empty instead.
doc.css('Object').each do |element|
element.attr("Id").value = timestamp
end
However this returns with the error that value= is an undefined method. It's probably something simple but I'm new to Ruby and CSS so any help would be great.
The problem has little to do with CSS, since Nokogiri uses CSS selectors as an alternative to using XPath selectors, and both are only used to provide a path to a node, or nodes.
It looks like you're overthinking this, and making it harder than it needs to be. Here's what I'd do:
require 'nokogiri'
doc = Nokogiri::XML(<<EOT)
<xml>
<foo>
<Object>bar</Object>
</foo>
</xml>
EOT
doc.at('Object')["Id"] = Time.now.to_s
Looking at doc at this point shows:
puts doc.to_xml
# >> <?xml version="1.0"?>
# >> <xml>
# >> <foo>
# >> <Object Id="2014-01-28 19:13:32 -0700">bar</Object>
# >> </foo>
# >> </xml>
It's really important to understand the difference between at, at_css and at_xpath, which return the first matching Node, and search, css and xpath, which return NodeSets. A NodeSet is akin to an array containing Nodes. When you know that, your statement:
doc.css('Object').attr("Id").value = timestamp
won't make much sense, especially since that's not how the attr method is defined:
attr(key, value = nil, &blk)
You'd need to use:
doc.css('Object').attr("Id", value)
which would assign value to all Id attributes for every <Object> node in the document.
But, again, that's not the right choice, instead you should use at or at_css to return the single node.
This was fine until the situation where 'Object' doesn't exist
If no <Object> node exists, then it gets more interesting, and you have to determine what to do. You can insert it, or, you can simply move along and do nothing.
To see if a node exists is simple:
object_node = doc.at('Object')
if object_node
object_node['Id'] = Time.now.to_s
else
# ... insert it
end
To insert a node involves locating the place you want to insert it, then add it:
doc.at('foo').add_child("<Object Id='#{ Time.now }'>baz</Object>")
puts doc.to_xml
# >> <?xml version="1.0"?>
# >> <xml>
# >> <foo>
# >> <Object>bar</Object>
# >> <Object Id="2014-01-28 19:39:38 -0700">baz</Object></foo>
# >> </xml>
I didn't try to make the XML output pretty, which isn't important in XML, it merely needs to be syntactically correct.
Also note that it's possible to insert a node, or nodes, by defining them as a string of XML. Nokogiri will parse it into the appropriate XML and graft it in where you said. You could also go the long route by define a NodeSet or Node, then inserting it, but, in general, that makes uglier code and causes you to do a lot more work, which results in less readable code for those who follow in your footsteps maintaining the source.

Cucumber: In which order the feature tags are followed in a cucumber script?

I am facing an issue where I need to run script with three features. Let's say we have 3 feature files with tag names as #smoke1, #smoke2 and #smoke3. And I want these to be executed in that sequence.
Issue is that smoke3 is executing first and rest of them afterwards.
This is my script:
#Cucumber.Options(
glue = { "com.abc", "cucumber.runtime.java.spring.hooks" },
features = "classpath:",
format = { "json", "json:target/cucumber.json" },
tags = "#smoke1, #smoke2, #smoke3"
)
public class ex_Test extends AbstractTest { }
Warning: This only works in older versions of Cucumber.
Cucumber feature files are executed in alphabetical order by path and filename. The execution order is not based on tags.
However, if you specifically specify features, they should be run in the order declared.
For example:
#Cucumber.Options(features={"first_smoke.feature", "another_smoke.feature"})
Should run first_smoke and then another_smoke (compared to the default which is to run in the other order.
Ok we got it , We can have multiple tags for a single scenario like this #tag1 #tag2 #tag3.
You can not define the order in way below.
#Cucumber.Options(features={"first_smoke.feature", "another_smoke.feature"})
Cucumber determines the only alphabetical order and even only first letter of the word.
You can have how many tags you want in feature file, if you want to trigger feature file more times, it's not working like you will add tag more time or more tags from feature like:
tags = {"#Reports,#Reports"}
And tests are triggered in alphabetical order, it's checking tags not feature file name.

How do I edit the VIM Omni Completion so that all CSS properties do not end in a colon?

I have been exploring some way in VIM to automatically append closing characters to a line of code. In my case it is CSS. I came across this tip http://vim.wikia.com/wiki/Automatically_append_closing_characters and tweaked the code it tells me to add to my .vimrc like so
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
so when I write
body
and then press { and ENTER in rapid succession what results is
body {
}
Note that the cursor will be indented and on the 2nd line so I will be ready to write code in that block.
Also I should mention that I also added the following to my .vimrc
inoremap :: :;<Left>
so that when I type : and : in rapid succession I will get :; with the cursor located in between the : and ;. This exactly where I want to be so I can start writing code right away.
I got that working fine but I quickly realized that the auto complete plug in that I installed (AutoComplPop VIM plug-in http://www.vim.org/scripts/script.php?script_id=1879) conflicts with the above .vimrc tweak.
So for example, if I start to write color I get the drop auto completion drop down menu of all options. The problem is that the option for color is actually color:.
You see it has a colon already added to it so when I select it, the colon is already there and then I have to manually add the closing ; character. This basically defeats the whole purpose of adding the auto appending closing character code to my .vimrc since in this case, it does not auto append the closing semicolon.
So how do I make a custom edit to VIM's Omni Completion so that all CSS properties do not end in a colon?
CSS auto completion options for VIM and came across AutoComplPop here http://www.vim.org/scripts/script.php?script_id=1879
Assuming you are on a UNIX-like system…
Copy
/usr/share/vim/vim7x/autoload/csscomplete.vim
to
~/.vim/autoload/csscomplete.vim
Find the loop that generates the list of properties, for me it's at line 92.
Remove the colon from the second parameter of the two add().
These lines:
call add(res, m . ':')
call add(res2, m . ':')
become:
call add(res, m)
call add(res2, m)
Save the file.
Also there are many plugins for "auto closing" pairs of characters. I use DelimitMate.
And the issue is not related to ACP at all.

Resources