update_engine: remove gflags dependency

We are switching to using chromeos/flag_helper.h instead to standardize the
code everywhere.

BUG=chromium:402636
TEST=`FEATURES=test emerge-panther update_engine`
CQ-DEPEND=I03b10d9e6148f1704de7a60128e1550156519272
CQ-DEPEND=I79112aa60d1f27ff0e5b8ee96f1ae46ee9a89a59
CQ-DEPEND=I6d08c080b6dafd59b23bbf185298c587e581c2ed
CQ-DEPEND=I218f6eab28b0160e8379a2716f5c33edeaf9841d

Change-Id: I81d0159f677b02a25640093c039c11e230af9b1b
Reviewed-on: https://chromium-review.googlesource.com/223216
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Steve Fung <stevefung@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Steve Fung <stevefung@chromium.org>
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index 9292cab..44ecb64 100644
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -214,8 +214,8 @@
     signature_size_string = base::StringPrintf("%d", signature_size);
   ASSERT_EQ(0,
             System(base::StringPrintf(
-                "./delta_generator -in_file %s -signature_size %s "
-                "-out_hash_file %s",
+                "./delta_generator -in_file=%s -signature_size=%s "
+                "-out_hash_file=%s",
                 payload_path.c_str(),
                 signature_size_string.c_str(),
                 hash_file.c_str())));
@@ -254,14 +254,14 @@
 
   ASSERT_EQ(0,
             System(base::StringPrintf(
-                "./delta_generator -in_file %s -signature_file %s "
-                "-out_file %s",
+                "./delta_generator -in_file=%s -signature_file=%s "
+                "-out_file=%s",
                 payload_path.c_str(),
                 sig_file.c_str(),
                 payload_path.c_str())));
   int verify_result =
       System(base::StringPrintf(
-          "./delta_generator -in_file %s -public_key %s -public_key_version %d",
+          "./delta_generator -in_file=%s -public_key=%s -public_key_version=%d",
           payload_path.c_str(),
           signature_test == kSignatureGeneratedShellRotateCl2 ?
           kUnittestPublicKey2Path : kUnittestPublicKeyPath,
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index 15e379f..b08e47d 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -12,11 +12,10 @@
 #include <string>
 #include <vector>
 
-#include <base/command_line.h>
 #include <base/logging.h>
 #include <base/strings/string_number_conversions.h>
 #include <base/strings/string_split.h>
-#include <gflags/gflags.h>
+#include <chromeos/flag_helper.h>
 #include <glib.h>
 
 #include "update_engine/delta_performer.h"
@@ -29,79 +28,6 @@
 #include "update_engine/update_metadata.pb.h"
 #include "update_engine/utils.h"
 
-DEFINE_string(old_dir, "",
-              "Directory where the old rootfs is loop mounted read-only");
-DEFINE_string(new_dir, "",
-              "Directory where the new rootfs is loop mounted read-only");
-DEFINE_string(old_image, "", "Path to the old rootfs");
-DEFINE_string(new_image, "", "Path to the new rootfs");
-DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
-DEFINE_string(new_kernel, "", "Path to the new kernel partition image");
-DEFINE_string(in_file, "",
-              "Path to input delta payload file used to hash/sign payloads "
-              "and apply delta over old_image (for debugging)");
-DEFINE_string(out_file, "", "Path to output delta payload file");
-DEFINE_string(out_hash_file, "", "Path to output hash file");
-DEFINE_string(out_metadata_hash_file, "", "Path to output metadata hash file");
-DEFINE_string(private_key, "", "Path to private key in .pem format");
-DEFINE_string(public_key, "", "Path to public key in .pem format");
-DEFINE_int32(public_key_version,
-             chromeos_update_engine::kSignatureMessageCurrentVersion,
-             "Key-check version # of client");
-DEFINE_string(prefs_dir, "/tmp/update_engine_prefs",
-              "Preferences directory, used with apply_delta");
-DEFINE_string(signature_size, "",
-              "Raw signature size used for hash calculation. "
-              "You may pass in multiple sizes by colon separating them. E.g. "
-              "2048:2048:4096 will assume 3 signatures, the first two with "
-              "2048 size and the last 4096.");
-DEFINE_string(signature_file, "",
-              "Raw signature file to sign payload with. To pass multiple "
-              "signatures, use a single argument with a colon between paths, "
-              "e.g. /path/to/sig:/path/to/next:/path/to/last_sig . Each "
-              "signature will be assigned a client version, starting from "
-              "kSignatureOriginalVersion.");
-DEFINE_int32(chunk_size, -1, "Payload chunk size (-1 -- no limit/default)");
-DEFINE_int64(rootfs_partition_size,
-             chromeos_update_engine::kRootFSPartitionSize,
-             "RootFS partition size for the image once installed");
-
-DEFINE_string(old_channel, "",
-              "The channel for the old image. 'dev-channel', 'npo-channel', "
-              "etc. Ignored, except during delta generation.");
-DEFINE_string(old_board, "",
-              "The board for the old image. 'x86-mario', 'lumpy', "
-              "etc. Ignored, except during delta generation.");
-DEFINE_string(old_version, "",
-              "The build version of the old image. 1.2.3, etc.");
-DEFINE_string(old_key, "",
-              "The key used to sign the old image. 'premp', 'mp', 'mp-v3',"
-              " etc");
-DEFINE_string(old_build_channel, "",
-              "The channel for the build of the old image. 'dev-channel', "
-              "etc, but will never contain special channels such as "
-              "'npo-channel'. Ignored, except during delta generation.");
-DEFINE_string(old_build_version, "",
-              "The version of the build containing the old image.");
-
-DEFINE_string(new_channel, "",
-              "The channel for the new image. 'dev-channel', 'npo-channel', "
-              "etc. Ignored, except during delta generation.");
-DEFINE_string(new_board, "",
-              "The board for the new image. 'x86-mario', 'lumpy', "
-              "etc. Ignored, except during delta generation.");
-DEFINE_string(new_version, "",
-              "The build version of the new image. 1.2.3, etc.");
-DEFINE_string(new_key, "",
-              "The key used to sign the new image. 'premp', 'mp', 'mp-v3',"
-              " etc");
-DEFINE_string(new_build_channel, "",
-              "The channel for the build of the new image. 'dev-channel', "
-              "etc, but will never contain special channels such as "
-              "'npo-channel'. Ignored, except during delta generation.");
-DEFINE_string(new_build_version, "",
-              "The version of the build containing the new image.");
-
 // This file contains a simple program that takes an old path, a new path,
 // and an output file as arguments and the path to an output file and
 // generates a delta that can be sent to Chrome OS clients.
@@ -169,15 +95,16 @@
 }
 
 void CalculatePayloadHashForSigning(const vector<int> &sizes,
-                                    const string& out_hash_file) {
+                                    const string& out_hash_file,
+                                    const string& in_file) {
   LOG(INFO) << "Calculating payload hash for signing.";
-  LOG_IF(FATAL, FLAGS_in_file.empty())
+  LOG_IF(FATAL, in_file.empty())
       << "Must pass --in_file to calculate hash for signing.";
   LOG_IF(FATAL, out_hash_file.empty())
       << "Must pass --out_hash_file to calculate hash for signing.";
 
   vector<char> hash;
-  bool result = PayloadSigner::HashPayloadForSigning(FLAGS_in_file, sizes,
+  bool result = PayloadSigner::HashPayloadForSigning(in_file, sizes,
                                                      &hash);
   CHECK(result);
 
@@ -188,15 +115,16 @@
 
 
 void CalculateMetadataHashForSigning(const vector<int> &sizes,
-                                     const string& out_metadata_hash_file) {
+                                     const string& out_metadata_hash_file,
+                                     const string& in_file) {
   LOG(INFO) << "Calculating metadata hash for signing.";
-  LOG_IF(FATAL, FLAGS_in_file.empty())
+  LOG_IF(FATAL, in_file.empty())
       << "Must pass --in_file to calculate metadata hash for signing.";
   LOG_IF(FATAL, out_metadata_hash_file.empty())
       << "Must pass --out_metadata_hash_file to calculate metadata hash.";
 
   vector<char> hash;
-  bool result = PayloadSigner::HashMetadataForSigning(FLAGS_in_file, sizes,
+  bool result = PayloadSigner::HashMetadataForSigning(in_file, sizes,
                                                       &hash);
   CHECK(result);
 
@@ -207,17 +135,19 @@
   LOG(INFO) << "Done calculating metadata hash for signing.";
 }
 
-void SignPayload() {
+void SignPayload(const string& in_file,
+                 const string& out_file,
+                 const string& signature_file) {
   LOG(INFO) << "Signing payload.";
-  LOG_IF(FATAL, FLAGS_in_file.empty())
+  LOG_IF(FATAL, in_file.empty())
       << "Must pass --in_file to sign payload.";
-  LOG_IF(FATAL, FLAGS_out_file.empty())
+  LOG_IF(FATAL, out_file.empty())
       << "Must pass --out_file to sign payload.";
-  LOG_IF(FATAL, FLAGS_signature_file.empty())
+  LOG_IF(FATAL, signature_file.empty())
       << "Must pass --signature_file to sign payload.";
   vector<vector<char>> signatures;
   vector<string> signature_files;
-  base::SplitString(FLAGS_signature_file, ':', &signature_files);
+  base::SplitString(signature_file, ':', &signature_files);
   for (vector<string>::iterator it = signature_files.begin(),
            e = signature_files.end(); it != e; ++it) {
     vector<char> signature;
@@ -226,49 +156,54 @@
   }
   uint64_t final_metadata_size;
   CHECK(PayloadSigner::AddSignatureToPayload(
-      FLAGS_in_file, signatures, FLAGS_out_file, &final_metadata_size));
+      in_file, signatures, out_file, &final_metadata_size));
   LOG(INFO) << "Done signing payload. Final metadata size = "
             << final_metadata_size;
 }
 
-void VerifySignedPayload() {
+void VerifySignedPayload(const string& in_file,
+                         const string& public_key,
+                         int public_key_version) {
   LOG(INFO) << "Verifying signed payload.";
-  LOG_IF(FATAL, FLAGS_in_file.empty())
+  LOG_IF(FATAL, in_file.empty())
       << "Must pass --in_file to verify signed payload.";
-  LOG_IF(FATAL, FLAGS_public_key.empty())
+  LOG_IF(FATAL, public_key.empty())
       << "Must pass --public_key to verify signed payload.";
-  CHECK(PayloadVerifier::VerifySignedPayload(FLAGS_in_file, FLAGS_public_key,
-                                             FLAGS_public_key_version));
+  CHECK(PayloadVerifier::VerifySignedPayload(in_file, public_key,
+                                             public_key_version));
   LOG(INFO) << "Done verifying signed payload.";
 }
 
-void ApplyDelta() {
+void ApplyDelta(const string& in_file,
+                const string& old_kernel,
+                const string& old_image,
+                const string& prefs_dir) {
   LOG(INFO) << "Applying delta.";
-  LOG_IF(FATAL, FLAGS_old_image.empty())
+  LOG_IF(FATAL, old_image.empty())
       << "Must pass --old_image to apply delta.";
   Prefs prefs;
   InstallPlan install_plan;
-  LOG(INFO) << "Setting up preferences under: " << FLAGS_prefs_dir;
-  LOG_IF(ERROR, !prefs.Init(base::FilePath(FLAGS_prefs_dir)))
+  LOG(INFO) << "Setting up preferences under: " << prefs_dir;
+  LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
       << "Failed to initialize preferences.";
   // Get original checksums
   LOG(INFO) << "Calculating original checksums";
   PartitionInfo kern_info, root_info;
   CHECK(DeltaDiffGenerator::InitializePartitionInfo(true,  // is_kernel
-                                                    FLAGS_old_kernel,
+                                                    old_kernel,
                                                     &kern_info));
   CHECK(DeltaDiffGenerator::InitializePartitionInfo(false,  // is_kernel
-                                                    FLAGS_old_image,
+                                                    old_image,
                                                     &root_info));
   install_plan.kernel_hash.assign(kern_info.hash().begin(),
                                   kern_info.hash().end());
   install_plan.rootfs_hash.assign(root_info.hash().begin(),
                                   root_info.hash().end());
   DeltaPerformer performer(&prefs, nullptr, &install_plan);
-  CHECK_EQ(performer.Open(FLAGS_old_image.c_str(), 0, 0), 0);
-  CHECK(performer.OpenKernel(FLAGS_old_kernel.c_str()));
+  CHECK_EQ(performer.Open(old_image.c_str(), 0, 0), 0);
+  CHECK(performer.OpenKernel(old_kernel.c_str()));
   vector<char> buf(1024 * 1024);
-  int fd = open(FLAGS_in_file.c_str(), O_RDONLY, 0);
+  int fd = open(in_file.c_str(), O_RDONLY, 0);
   CHECK_GE(fd, 0);
   ScopedFdCloser fd_closer(&fd);
   for (off_t offset = 0;; offset += buf.size()) {
@@ -284,13 +219,85 @@
 }
 
 int Main(int argc, char** argv) {
-  google::SetUsageMessage(
+  DEFINE_string(old_dir, "",
+                "Directory where the old rootfs is loop mounted read-only");
+  DEFINE_string(new_dir, "",
+                "Directory where the new rootfs is loop mounted read-only");
+  DEFINE_string(old_image, "", "Path to the old rootfs");
+  DEFINE_string(new_image, "", "Path to the new rootfs");
+  DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
+  DEFINE_string(new_kernel, "", "Path to the new kernel partition image");
+  DEFINE_string(in_file, "",
+                "Path to input delta payload file used to hash/sign payloads "
+                "and apply delta over old_image (for debugging)");
+  DEFINE_string(out_file, "", "Path to output delta payload file");
+  DEFINE_string(out_hash_file, "", "Path to output hash file");
+  DEFINE_string(out_metadata_hash_file, "",
+                "Path to output metadata hash file");
+  DEFINE_string(private_key, "", "Path to private key in .pem format");
+  DEFINE_string(public_key, "", "Path to public key in .pem format");
+  DEFINE_int32(public_key_version,
+               chromeos_update_engine::kSignatureMessageCurrentVersion,
+               "Key-check version # of client");
+  DEFINE_string(prefs_dir, "/tmp/update_engine_prefs",
+                "Preferences directory, used with apply_delta");
+  DEFINE_string(signature_size, "",
+                "Raw signature size used for hash calculation. "
+                "You may pass in multiple sizes by colon separating them. E.g. "
+                "2048:2048:4096 will assume 3 signatures, the first two with "
+                "2048 size and the last 4096.");
+  DEFINE_string(signature_file, "",
+                "Raw signature file to sign payload with. To pass multiple "
+                "signatures, use a single argument with a colon between paths, "
+                "e.g. /path/to/sig:/path/to/next:/path/to/last_sig . Each "
+                "signature will be assigned a client version, starting from "
+                "kSignatureOriginalVersion.");
+  DEFINE_int32(chunk_size, -1, "Payload chunk size (-1 -- no limit/default)");
+  DEFINE_int64(rootfs_partition_size,
+               chromeos_update_engine::kRootFSPartitionSize,
+               "RootFS partition size for the image once installed");
+
+  DEFINE_string(old_channel, "",
+                "The channel for the old image. 'dev-channel', 'npo-channel', "
+                "etc. Ignored, except during delta generation.");
+  DEFINE_string(old_board, "",
+                "The board for the old image. 'x86-mario', 'lumpy', "
+                "etc. Ignored, except during delta generation.");
+  DEFINE_string(old_version, "",
+                "The build version of the old image. 1.2.3, etc.");
+  DEFINE_string(old_key, "",
+                "The key used to sign the old image. 'premp', 'mp', 'mp-v3',"
+                " etc");
+  DEFINE_string(old_build_channel, "",
+                "The channel for the build of the old image. 'dev-channel', "
+                "etc, but will never contain special channels such as "
+                "'npo-channel'. Ignored, except during delta generation.");
+  DEFINE_string(old_build_version, "",
+                "The version of the build containing the old image.");
+
+  DEFINE_string(new_channel, "",
+                "The channel for the new image. 'dev-channel', 'npo-channel', "
+                "etc. Ignored, except during delta generation.");
+  DEFINE_string(new_board, "",
+                "The board for the new image. 'x86-mario', 'lumpy', "
+                "etc. Ignored, except during delta generation.");
+  DEFINE_string(new_version, "",
+                "The build version of the new image. 1.2.3, etc.");
+  DEFINE_string(new_key, "",
+                "The key used to sign the new image. 'premp', 'mp', 'mp-v3',"
+                " etc");
+  DEFINE_string(new_build_channel, "",
+                "The channel for the build of the new image. 'dev-channel', "
+                "etc, but will never contain special channels such as "
+                "'npo-channel'. Ignored, except during delta generation.");
+  DEFINE_string(new_build_version, "",
+                "The version of the build containing the new image.");
+
+  chromeos::FlagHelper::Init(argc, argv,
       "Generates a payload to provide to ChromeOS' update_engine.\n\n"
       "This tool can create full payloads and also delta payloads if the src\n"
       "image is provided. It also provides debugging options to apply, sign\n"
       "and verify payloads.");
-  google::ParseCommandLineFlags(&argc, &argv, true);
-  CommandLine::Init(argc, argv);
   Terminator::Init();
   Subprocess::Init();
 
@@ -307,24 +314,28 @@
 
   if (!FLAGS_out_hash_file.empty() || !FLAGS_out_metadata_hash_file.empty()) {
     if (!FLAGS_out_hash_file.empty()) {
-      CalculatePayloadHashForSigning(signature_sizes, FLAGS_out_hash_file);
+      CalculatePayloadHashForSigning(signature_sizes, FLAGS_out_hash_file,
+                                     FLAGS_in_file);
     }
     if (!FLAGS_out_metadata_hash_file.empty()) {
       CalculateMetadataHashForSigning(signature_sizes,
-                                      FLAGS_out_metadata_hash_file);
+                                      FLAGS_out_metadata_hash_file,
+                                      FLAGS_in_file);
     }
     return 0;
   }
   if (!FLAGS_signature_file.empty()) {
-    SignPayload();
+    SignPayload(FLAGS_in_file, FLAGS_out_file, FLAGS_signature_file);
     return 0;
   }
   if (!FLAGS_public_key.empty()) {
-    VerifySignedPayload();
+    VerifySignedPayload(FLAGS_in_file, FLAGS_public_key,
+                        FLAGS_public_key_version);
     return 0;
   }
   if (!FLAGS_in_file.empty()) {
-    ApplyDelta();
+    ApplyDelta(FLAGS_in_file, FLAGS_old_kernel, FLAGS_old_image,
+               FLAGS_prefs_dir);
     return 0;
   }
   CHECK(!FLAGS_new_image.empty());
diff --git a/update_engine.gyp b/update_engine.gyp
index 83269c9..aeb4bad 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -125,7 +125,6 @@
         },
         'libraries': [
           '-lbz2',
-          '-lgflags',
           '-lpolicy-<(libbase_ver)',
           '-lrootdev',
           '-lrt',
@@ -227,9 +226,6 @@
             '<@(exported_deps)',
           ],
         },
-        'libraries': [
-          '-lgflags',
-        ],
       },
       'sources': [
         'glib_utils.cc',
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 37d52d6..0fe511c 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -6,9 +6,10 @@
 
 #include <base/logging.h>
 #include <chromeos/dbus/service_constants.h>
+#include <chromeos/flag_helper.h>
 #include <dbus/dbus.h>
-#include <gflags/gflags.h>
 #include <glib.h>
+#include <inttypes.h>
 
 #include "update_engine/dbus_constants.h"
 #include "update_engine/glib_utils.h"
@@ -25,48 +26,6 @@
 using chromeos_update_engine::utils::GetAndFreeGError;
 using std::string;
 
-DEFINE_string(app_version, "", "Force the current app version.");
-DEFINE_string(channel, "",
-              "Set the target channel. The device will be powerwashed if the "
-              "target channel is more stable than the current channel unless "
-              "--nopowerwash is specified.");
-DEFINE_bool(check_for_update, false, "Initiate check for updates.");
-DEFINE_bool(follow, false, "Wait for any update operations to complete."
-            "Exit status is 0 if the update succeeded, and 1 otherwise.");
-DEFINE_bool(interactive, true, "Mark the update request as interactive.");
-DEFINE_string(omaha_url, "", "The URL of the Omaha update server.");
-DEFINE_string(p2p_update, "",
-              "Enables (\"yes\") or disables (\"no\") the peer-to-peer update "
-              "sharing.");
-DEFINE_bool(powerwash, true, "When performing rollback or channel change, "
-            "do a powerwash or allow it respectively.");
-DEFINE_bool(reboot, false, "Initiate a reboot if needed.");
-DEFINE_bool(is_reboot_needed, false, "Exit status 0 if reboot is needed, "
-            "2 if reboot is not needed or 1 if an error occurred.");
-DEFINE_bool(block_until_reboot_is_needed, false, "Blocks until reboot is "
-            "needed. Returns non-zero exit status if an error occurred.");
-DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle.");
-DEFINE_bool(rollback, false, "Perform a rollback to the previous partition.");
-DEFINE_bool(can_rollback, false, "Shows whether rollback partition "
-            "is available.");
-DEFINE_bool(show_channel, false, "Show the current and target channels.");
-DEFINE_bool(show_p2p_update, false,
-            "Show the current setting for peer-to-peer update sharing.");
-DEFINE_bool(show_update_over_cellular, false,
-            "Show the current setting for updates over cellular networks.");
-DEFINE_bool(status, false, "Print the status to stdout.");
-DEFINE_bool(update, false, "Forces an update and waits for it to complete. "
-            "Implies --follow.");
-DEFINE_string(update_over_cellular, "",
-              "Enables (\"yes\") or disables (\"no\") the updates over "
-              "cellular networks.");
-DEFINE_bool(watch_for_updates, false,
-            "Listen for status updates and print them to the screen.");
-DEFINE_bool(prev_version, false,
-            "Show the previous OS version used before the update reboot.");
-DEFINE_bool(show_kernels, false, "Show the list of kernel patritions and "
-            "whether each of them is bootable or not");
-
 namespace {
 
 bool GetProxy(DBusGProxy** out_proxy) {
@@ -252,14 +211,16 @@
   return devices;
 }
 
-bool CheckForUpdates(const string& app_version, const string& omaha_url) {
+bool CheckForUpdates(const string& app_version,
+                     const string& omaha_url,
+                     bool interactive) {
   DBusGProxy* proxy;
   GError* error = nullptr;
 
   CHECK(GetProxy(&proxy));
 
   AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(
-      FLAGS_interactive ? 0 : kAttemptUpdateFlagNonInteractive);
+      interactive ? 0 : kAttemptUpdateFlagNonInteractive);
   gboolean rc =
       update_engine_client_attempt_update_with_flags(proxy,
                                                      app_version.c_str(),
@@ -532,10 +493,52 @@
 }  // namespace
 
 int main(int argc, char** argv) {
+  DEFINE_string(app_version, "", "Force the current app version.");
+  DEFINE_string(channel, "",
+                "Set the target channel. The device will be powerwashed if the "
+                "target channel is more stable than the current channel unless "
+                "--nopowerwash is specified.");
+  DEFINE_bool(check_for_update, false, "Initiate check for updates.");
+  DEFINE_bool(follow, false, "Wait for any update operations to complete."
+              "Exit status is 0 if the update succeeded, and 1 otherwise.");
+  DEFINE_bool(interactive, true, "Mark the update request as interactive.");
+  DEFINE_string(omaha_url, "", "The URL of the Omaha update server.");
+  DEFINE_string(p2p_update, "",
+                "Enables (\"yes\") or disables (\"no\") the peer-to-peer update"
+                " sharing.");
+  DEFINE_bool(powerwash, true, "When performing rollback or channel change, "
+              "do a powerwash or allow it respectively.");
+  DEFINE_bool(reboot, false, "Initiate a reboot if needed.");
+  DEFINE_bool(is_reboot_needed, false, "Exit status 0 if reboot is needed, "
+              "2 if reboot is not needed or 1 if an error occurred.");
+  DEFINE_bool(block_until_reboot_is_needed, false, "Blocks until reboot is "
+              "needed. Returns non-zero exit status if an error occurred.");
+  DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle.");
+  DEFINE_bool(rollback, false, "Perform a rollback to the previous partition.");
+  DEFINE_bool(can_rollback, false, "Shows whether rollback partition "
+              "is available.");
+  DEFINE_bool(show_channel, false, "Show the current and target channels.");
+  DEFINE_bool(show_p2p_update, false,
+              "Show the current setting for peer-to-peer update sharing.");
+  DEFINE_bool(show_update_over_cellular, false,
+              "Show the current setting for updates over cellular networks.");
+  DEFINE_bool(status, false, "Print the status to stdout.");
+  DEFINE_bool(update, false, "Forces an update and waits for it to complete. "
+              "Implies --follow.");
+  DEFINE_string(update_over_cellular, "",
+                "Enables (\"yes\") or disables (\"no\") the updates over "
+                "cellular networks.");
+  DEFINE_bool(watch_for_updates, false,
+              "Listen for status updates and print them to the screen.");
+  DEFINE_bool(prev_version, false,
+              "Show the previous OS version used before the update reboot.");
+  DEFINE_bool(show_kernels, false, "Show the list of kernel patritions and "
+              "whether each of them is bootable or not");
+
   // Boilerplate init commands.
   g_type_init();
   dbus_threads_init_default();
-  google::ParseCommandLineFlags(&argc, &argv, true);
+  chromeos::FlagHelper::Init(argc, argv, "Chromium OS Update Engine Client");
 
   // Update the status if requested.
   if (FLAGS_reset_status) {
@@ -646,7 +649,7 @@
       LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate.";
     }
     LOG(INFO) << "Initiating update check and install.";
-    CHECK(CheckForUpdates(app_version, FLAGS_omaha_url))
+    CHECK(CheckForUpdates(app_version, FLAGS_omaha_url, FLAGS_interactive))
         << "Update check/initiate update failed.";
   }