Share common code in logic and api commands