0

I want to execute all sub command in cobra. Is there any way to achive this?

think that you want to create tcp packet so you need to use tcp command with flags and ipv4 command with flags. If you want to create dns packet so you will need to dns command with flags, udp command with flags and ipv4 command with flags.

For example,

root <root flags> tcp <tcp flags> ipv4 <ipv4 flags>

OR

root <root flags> dns <dns flags> udp <udp flags> ipv4 <ipv4 flags>

So I want to execute subsub command and sub command when write like above. But only execute last command.

Rasit aydin
  • 419
  • 2
  • 6
  • 16
  • I would be very surprised if this is possible from cobra directly. Many/most subcommands will have conflicting options, so automating this would be impossible in most cases. I assume this is for testing of some sort. Your best bet is probably a bash script. – Jonathan Hall Mar 25 '20 at 09:10
  • @Flimzy actually in my case task is one commands are options. for example u want to create tcp packet so you need tcp command with flags and ipv4 command with flags. If you want to create dns packet you will need to dns command with flags, udp command with flags and ipv4 command with flags. I didn't figure out how can i achive this pattern. I am stuck... :) – Rasit aydin Mar 25 '20 at 09:20
  • So you're trying to do some sort of chaining of subcommands? I suggest updating your question to be more specific on the actual goal you're trying to achieve. – Jonathan Hall Mar 25 '20 at 09:55
  • @Flimzy thanks I edited my question. Let me ask to you some thing else about cobra. I am trying to use Execute and Parent functions to build this chaining. In reverse manner maybe this is possible. For example, not first tcp but ipv4 `root ipv4 tcp ` so in tcp command I can find parent command with Parent method. But When I use Execute function this function only executes RUN method not Init method. Is there any way to run just init method for any command ? – Rasit aydin Mar 25 '20 at 10:18
  • got a good way to achieve this? – amarjeetAnand Aug 14 '20 at 07:42

0 Answers0