Also, how would a newly promoted lieutenant or commander go about getting a new uniform that conformed to Naval regulations at the time?
It's not a button he wants Mercedes to sew on -- part of the joke throughout is that he's utterly incompetent at languages despite trying what he thinks sounds like Spanish, etc. The passage reads:
“He was exceedingly hungry and thirsty: he darted to the bell and pulled it violently, but before the rope had stopped quivering his head was out in the corridor and he was hailing the chambermaid. 'Mercy! Mercy! Oh, there you are, my dear. What can you bring me to eat, manger, mangiare? Polio? Cold roast polio? And a bottle of wine, vino - two bottles of vino. And Mercy, will you come and do something for me? I want you, desirer, to do something for me, eh? Sew on, cosare, a button.'
'Yes, Teniente,' said Mercedes, her eyes rolling in the candlelight and her teeth flashing white.
'Not teniente,' cried Jack, crushing the breath out of her plump, supple body. 'Capitan! Capitano, ha, ha, ha!”
What he does on the next page is to go to a naval outfitters' shop and buy a epaulette (on credit) or shoulder board. This was a relatively recent innovation in the RN -- epaulettes had only become part of rank insignia in 1795, and in Aubrey's time (his promotion dates to April 1, 1800) you could distinguish a commander and a junior post-captain by what shoulder their epaulettes were on. A commander would wear his on the left shoulder, and a post-captain his on the right shoulder until he attained three years' seniority, upon which he could wear a epaulette on each shoulder. After 1812 this changed again, with lieutenants entitled to a epaulette and commanders entitled to two, with rank markings for captains and admirals. But Jack just needed one in his time.
I wrote a bunch before about rank structures in the RN, if you have follow up questions.