@@ -157,6 +157,28 @@ void RenameObject(google::cloud::storage::Client client,
157157 (std::move (client), argv.at (0 ), argv.at (1 ), argv.at (2 ));
158158}
159159
160+ void MoveObject (google::cloud::storage::Client client,
161+ std::vector<std::string> const & argv) {
162+ // ! [move_object] [START storage_move_object]
163+ namespace gcs = ::google::cloud::storage;
164+ using ::google::cloud::StatusOr;
165+ [](gcs::Client client, std::string const & bucket_name,
166+ std::string const & source_object_name,
167+ std::string const & destination_object_name) {
168+ StatusOr<gcs::ObjectMetadata> metadata = client.MoveObject (
169+ bucket_name, source_object_name, destination_object_name);
170+ if (!metadata) throw std::move (metadata).status ();
171+
172+ std::cout << " Successfully renamed " << source_object_name << " to "
173+ << destination_object_name << " in bucket " << bucket_name
174+ << " .\n " ;
175+ }
176+
177+ // ! [move_object] [END storage_move_object]
178+ (std::move (client), argv.at (0 ), argv.at (1 ), argv.at (2 ));
179+ }
180+
181+
160182void RunAll (std::vector<std::string> const & argv) {
161183 namespace examples = ::google::cloud::storage::examples;
162184 namespace gcs = ::google::cloud::storage;
@@ -251,6 +273,16 @@ void RunAll(std::vector<std::string> const& argv) {
251273
252274 (void )client.DeleteObject (destination_bucket_name, dst_object_name);
253275 (void )client.DeleteObject (bucket_name, src_object_name);
276+
277+ std::cout << " \n Creating an object to run the MoveObject() example"
278+ << std::endl;
279+ (void )client.InsertObject (bucket_name, old_object_name, kText ).value ();
280+
281+ std::cout << " \n Running the MoveObject() example" << std::endl;
282+ MoveObject (client, {bucket_name, old_object_name, new_object_name});
283+
284+ std::cout << " \n Cleanup" << std::endl;
285+ (void )client.DeleteObject (bucket_name, new_object_name);
254286}
255287
256288} // namespace
@@ -275,6 +307,10 @@ int main(int argc, char* argv[]) {
275307 " rename-object" ,
276308 {" <bucket-name>" , " <old-object-name>" , " <new-object-name>" },
277309 RenameObject),
310+ examples::CreateCommandEntry (
311+ " move-object" ,
312+ {" <bucket-name>" , " <source-object-name>" , " <destination-object-name>" },
313+ MoveObject),
278314 {" auto" , RunAll},
279315 });
280316 return example.Run (argc, argv);
0 commit comments