From 22b804bd2deddf34b628a097c45abcf2d5d2cf2f Mon Sep 17 00:00:00 2001 From: Laramie Leavitt Date: Fri, 11 Oct 2024 12:01:13 -0700 Subject: [PATCH] Add an initial tensorstore cli tool. Currently supports: * tscli list --source [globs...] * tscli copy --source --target * tscli search --source * tscli print_spec --spec * tscli print_stats --spec [boxes...] PiperOrigin-RevId: 684912204 Change-Id: I13229643fc65d3352670dbdc5a62fdd016259ec6 --- tensorstore/tscli/BUILD | 84 ++++++++++++ tensorstore/tscli/args.cc | 198 ++++++++++++++++++++++++++++ tensorstore/tscli/args.h | 56 ++++++++ tensorstore/tscli/args_test.cc | 37 ++++++ tensorstore/tscli/cli.h | 37 ++++++ tensorstore/tscli/kvstore_copy.cc | 144 ++++++++++++++++++++ tensorstore/tscli/kvstore_list.cc | 144 ++++++++++++++++++++ tensorstore/tscli/main.cc | 145 ++++++++++++++++++++ tensorstore/tscli/ts_print_spec.cc | 75 +++++++++++ tensorstore/tscli/ts_print_stats.cc | 108 +++++++++++++++ tensorstore/tscli/ts_search.cc | 175 ++++++++++++++++++++++++ 11 files changed, 1203 insertions(+) create mode 100644 tensorstore/tscli/BUILD create mode 100644 tensorstore/tscli/args.cc create mode 100644 tensorstore/tscli/args.h create mode 100644 tensorstore/tscli/args_test.cc create mode 100644 tensorstore/tscli/cli.h create mode 100644 tensorstore/tscli/kvstore_copy.cc create mode 100644 tensorstore/tscli/kvstore_list.cc create mode 100644 tensorstore/tscli/main.cc create mode 100644 tensorstore/tscli/ts_print_spec.cc create mode 100644 tensorstore/tscli/ts_print_stats.cc create mode 100644 tensorstore/tscli/ts_search.cc diff --git a/tensorstore/tscli/BUILD b/tensorstore/tscli/BUILD new file mode 100644 index 00000000..59054a2f --- /dev/null +++ b/tensorstore/tscli/BUILD @@ -0,0 +1,84 @@ +load("//bazel:tensorstore.bzl", "tensorstore_cc_binary", "tensorstore_cc_library", "tensorstore_cc_test") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +tensorstore_cc_test( + name = "args_test", + srcs = ["args_test.cc"], + deps = [ + ":tsclilib", + "@com_google_googletest//:gtest_main", + ], +) + +tensorstore_cc_library( + name = "tsclilib", + srcs = [ + "args.cc", + "kvstore_copy.cc", + "kvstore_list.cc", + "ts_print_spec.cc", + "ts_print_stats.cc", + "ts_search.cc", + ], + hdrs = [ + "args.h", + "cli.h", + ], + deps = [ + "//tensorstore", + "//tensorstore:array_storage_statistics", + "//tensorstore:box", + "//tensorstore:context", + "//tensorstore:open", + "//tensorstore:open_mode", + "//tensorstore:spec", + "//tensorstore/index_space:dim_expression", + "//tensorstore/internal:path", + "//tensorstore/internal/json_binding", + "//tensorstore/kvstore", + "//tensorstore/kvstore:generation", + "//tensorstore/kvstore:key_range", + "//tensorstore/util:executor", + "//tensorstore/util:future", + "//tensorstore/util:json_absl_flag", + "//tensorstore/util:quote_string", + "//tensorstore/util:result", + "//tensorstore/util:span", + "//tensorstore/util:status", + "@com_github_nlohmann_json//:json", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/flags:parse", + "@com_google_absl//absl/functional:function_ref", + "@com_google_absl//absl/log", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", + "@com_google_absl//absl/synchronization", + "@com_google_re2//:re2", + ], +) + +tensorstore_cc_binary( + name = "tscli", + srcs = [ + "main.cc", + ], + deps = [ + ":tsclilib", + "//tensorstore:context", + "//tensorstore/driver:all_drivers", + "//tensorstore/internal/metrics:collect", + "//tensorstore/internal/metrics:registry", + "//tensorstore/kvstore:all_drivers", + "//tensorstore/util:json_absl_flag", + "@com_google_absl//absl/base:log_severity", + "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/flags:parse", + "@com_google_absl//absl/log:globals", + "@com_google_absl//absl/log:initialize", + "@com_google_absl//absl/status", + ], +) diff --git a/tensorstore/tscli/args.cc b/tensorstore/tscli/args.cc new file mode 100644 index 00000000..c00bf2d5 --- /dev/null +++ b/tensorstore/tscli/args.cc @@ -0,0 +1,198 @@ +// Copyright 2024 The TensorStore Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "tensorstore/tscli/args.h" + +#include +#include +#include +#include +#include + +#include "absl/container/flat_hash_set.h" +#include "absl/status/status.h" +#include "absl/strings/ascii.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "absl/strings/strip.h" +#include "tensorstore/util/span.h" +#include "tensorstore/util/status.h" + +namespace tensorstore { +namespace cli { + +absl::Status TryParseOptions(CommandFlags& flags, + tensorstore::span