|
| 1 | +/- |
| 2 | + Copyright 2022-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +-/ |
| 16 | + |
| 17 | +import Lean.Data.Json.FromToJson |
| 18 | + |
| 19 | +import DiffTest.Main |
| 20 | +import DiffTest.Parser |
| 21 | + |
| 22 | +/-! This file provides a basic command line interface for authorization |
| 23 | + and validation. It uses the interface functions defined in `Difftest`. -/ |
| 24 | + |
| 25 | +open DiffTest |
| 26 | + |
| 27 | +def readFile (filename : String) : IO String := |
| 28 | + IO.FS.readFile filename |
| 29 | + |
| 30 | +def printUsage (err : String) : IO Unit := |
| 31 | + IO.println s!"{err}\nUsage: Cli <command> <file>" |
| 32 | + |
| 33 | +def main (args : List String) : IO Unit := |
| 34 | + match args.length with |
| 35 | + | 2 => do |
| 36 | + let command := args.get! 0 |
| 37 | + let filename := args.get! 1 |
| 38 | + let request ← readFile filename |
| 39 | + match command with |
| 40 | + | "authorize" => |
| 41 | + let response := isAuthorizedDRT request |
| 42 | + IO.println response |
| 43 | + | "validate" => |
| 44 | + let response := validateDRT request |
| 45 | + IO.println response |
| 46 | + | _ => printUsage s!"Invalid command `{command}` (expected `authorize` or `validate`)" |
| 47 | + | n => printUsage s!"Incorrect number of arguments (expected 2, but got {n})" |
0 commit comments