Jump to content


How to use the -x command line argument?


  • Please log in to reply
4 replies to this topic

#1 UnstoppableDrew

UnstoppableDrew

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 01 May 2018 - 07:40 PM

Can someone explain how you're supposed to use the -x flag with the command line client? The help text is really ambiguous and the various things I've tried all haven't worked.
The specific thing I'm trying to do is delete a lot of labels. I figured I could put the list of label names in the file then do 'p4 -x my_labels.txt label -d' but the just gives me a Missing/wrong number of arguments error.

#2 Matt Janulewicz

Matt Janulewicz

    Advanced Member

  • Members
  • PipPipPip
  • 230 posts
  • LocationSan Diego, CA

Posted 01 May 2018 - 08:18 PM

In this case you'll have to use the '-b(atch)' argument and give it a '1' since 'p4 label' only takes one label at a time as an argument:

> p4 -x my_labels.txt -b 1 label -d

... should do it. By default, the batch size is 128 so it'll basically try to do a 'p4 label -d ...' with 128 labels at a time as arguments.
-Matt Janulewicz
Currently unemployed, looking for work in Boise, ID!

#3 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 1190 posts

Posted 01 May 2018 - 08:19 PM

Whatever you put in the file will be passed as individual arguments to the p4 command (it will not run the command once per arg -- important distinction).  Since "p4 label -d LABEL1 LABEL2 LABEL3" isn't valid syntax for the "label -d" command, you'll get a usage error if you pass a multi-line file in that way.

You might be able to use the built in "p4 run" command for this, though -- it's a sort of meta-command whose arguments are commands to run.  For example:

p4 -F "label -d %label%" labels -e EXPR | p4 -x - run

is the sort of thing you could use to delete a bunch of labels matching a particular expression.

The other option is the "xargs" shell command.  (Note that "p4 run" has a performance benefit -- it runs all the commands on the same connection, whereas "xargs" is going to invoke p4 multiple times and establish a new connection for each invocation.)

(edit) Matt's trick with the batch size is also good -- I'd forgotten you could use that to force single-arg invocations!

#4 UnstoppableDrew

UnstoppableDrew

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 02 May 2018 - 04:10 PM

Thanks, guys!

View PostSambwise, on 01 May 2018 - 08:19 PM, said:

p4 -F "label -d %label%" labels -e EXPR | p4 -x - run

I'm always impressed, both here & on Stack Exchange, with the way you combine static text & format strings to form commands for the next stage of a pipeline. I learned about this functionality relatively recently, and it has jumped to the top of my favorite features list for the stuff I do.

#5 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 1190 posts

Posted 02 May 2018 - 05:38 PM

View PostUnstoppableDrew, on 02 May 2018 - 04:10 PM, said:

Thanks, guys!

I'm always impressed, both here & on Stack Exchange, with the way you combine static text & format strings to form commands for the next stage of a pipeline. I learned about this functionality relatively recently, and it has jumped to the top of my favorite features list for the stuff I do.

Probably the single most useful feature I ever wrote and it's maybe 20 lines of code if that.  :P  https://swarm.worksh...tuserdbg.cc#103




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users