this is my assesment on afghanistan/iran because these two things are interlinked
a bit of backstory, the US has been getting beat in afghanistan, after 20 years and one trillion dollars they have only managed to occupy 38% of afghanistan, 15% is controlled by the taliban and the rest is still contested, things got so bad that they refused to give out data on afghanistan since april because all it showed was that the afghan resistance gained more and more ground
the US does not want to leave afghanistan, for it is the most important geostrategic location on earth, russia is not too far away, china is near, pakistan, india two nuclear nations, iran is right on the border, and afghanistan provides a gateway to the middle east, this is why the soviets had such a vested interest in afghanistan, so that they could use it to advance into the mid east, this is also why in the 19th and early 20th centuries the british and russians contested for control in afghanistan, but both of their invasions had failed
now as the war is being lost and making no gains, the invasion of iran would create the perfect turmoil which would justify american direct involvement in a nation that is directly hostile towards them, also opening the floodgates for more troops, they can justify involvement in afghanistan as well by saying "it's hitting two birds with one stone"
this is just the gist of it, it appears to me that trump does not war and it is actually the military industrial complex or the "establishment" of the US that would like to go to war which is why you might be seeing not very coherent decisions being made as a result of this power struggle between trump and the establishment