| // 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" |
| |
| "cos.googlesource.com/cos/tools.git/src/pkg/cosboot" |
| ) |
| |
| type showCmd struct{} |
| |
| func (*showCmd) Name() string { |
| return "show" |
| } |
| |
| func (*showCmd) Synopsis() string { |
| return "Show kernel arguments that will be used on the next boot." |
| } |
| |
| func (*showCmd) Usage() string { |
| return "show [disk image]\n" |
| } |
| |
| func (*showCmd) SetFlags(f *flag.FlagSet) {} |
| |
| func (*showCmd) showForGRUBBoot(disk string) subcommands.ExitStatus { |
| cmdLine, err := cosboot.NextGRUBCmdLine(disk) |
| if err != nil { |
| fmt.Printf("Error reading next GRUB command line: %v", err) |
| return subcommands.ExitFailure |
| } |
| fmt.Println(cmdLine) |
| return subcommands.ExitSuccess |
| } |
| |
| func (*showCmd) showForUKIBoot() subcommands.ExitStatus { |
| return subcommands.ExitSuccess |
| } |
| |
| func (c *showCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { |
| disk := "" |
| if f.NArg() > 0 { |
| disk = f.Arg(0) |
| } |
| |
| bootPath, err := cosboot.DiskBootPath(disk) |
| if err != nil { |
| fmt.Printf("Error identifying boot path: %v\n", err) |
| return subcommands.ExitFailure |
| } |
| |
| if bootPath == cosboot.GRUBBoot { |
| return c.showForGRUBBoot(disk) |
| } else if bootPath == cosboot.UKI { |
| return c.showForUKIBoot() |
| } else { |
| // This should never happen |
| fmt.Println("Could not identify boot path") |
| return subcommands.ExitFailure |
| } |
| } |