You can try mas-cli
(Mac Apple Store cli). Github project here
It would be
$ brew install mas
$ mas list
$ mas search Xcode
$ mas install <id>
$ mas upgrade <id>
upd:
Had issues installing Xcode 12.2 in Big Sur. Solved them by entering into the App Store from the devs link.