| // Copyright 2026 Google LLC |
| // |
| // 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. |
| |
| package main |
| |
| import ( |
| "context" |
| "flag" |
| "fmt" |
| |
| "github.com/google/subcommands" |
| ) |
| |
| type listCmd struct{} |
| |
| func (*listCmd) Name() string { |
| return "list" |
| } |
| |
| func (*listCmd) Synopsis() string { |
| return "Show current allowlist and enabled/disabled status" |
| } |
| |
| func (*listCmd) Usage() string { |
| return "list [disk image]\n" |
| } |
| |
| func (c *listCmd) SetFlags(f *flag.FlagSet) { |
| // No flags specific to list for now (disk is positional) |
| } |
| |
| func (c *listCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { |
| disk := "" |
| if f.NArg() > 0 { |
| disk = f.Arg(0) |
| } |
| |
| allowlist, _, err := readAllowlist(disk) |
| if err != nil { |
| fmt.Printf("Error reading allowlist: %v\n", err) |
| return subcommands.ExitFailure |
| } |
| |
| bitfield, err := readBitfield(disk) |
| if err != nil { |
| fmt.Printf("Error reading bitfield: %v\n", err) |
| return subcommands.ExitFailure |
| } |
| |
| fmt.Println("Allowed Arguments:") |
| if len(allowlist) == 0 { |
| fmt.Println(" (empty)") |
| } |
| for i, arg := range allowlist { |
| enabled := (bitfield & (1 << i)) != 0 |
| status := "[disabled]" |
| if enabled { |
| status = "[enabled] " |
| } |
| fmt.Printf(" %2d: %s %s\n", i, status, arg) |
| } |
| |
| return subcommands.ExitSuccess |
| } |